BlockAnchorSupportService.php
1 year ago
BlockPatternsService.php
1 year ago
BlockService.php
1 year ago
BlockServiceProvider.php
1 year ago
BlockStylesService.php
1 year ago
BlockValidationService.php
2 years ago
CartMenuIconMigrationService.php
1 year ago
CartMigrationService.php
1 year ago
FormModeSwitcherService.php
1 year ago
ProductCollectionBadgesMigrationService.php
1 year ago
ProductListMigrationService.php
1 year ago
ProductListService.php
1 year ago
ProductPageBlocksMigrationService.php
1 year ago
ProductPriceChoicesMigrationService.php
1 year ago
ProductSelectedPriceMigrationService.php
1 year ago
ProductVariantsMigrationService.php
1 year ago
URLParamService.php
1 year ago
ProductPriceChoicesMigrationService.php
123 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\BlockLibrary; |
| 4 | |
| 5 | /** |
| 6 | * Provide the migration service for the product price choices block. |
| 7 | */ |
| 8 | class ProductPriceChoicesMigrationService { |
| 9 | /** |
| 10 | * Attributes |
| 11 | * |
| 12 | * @var array |
| 13 | */ |
| 14 | public array $attributes = array(); |
| 15 | |
| 16 | /** |
| 17 | * Block. |
| 18 | * |
| 19 | * @var object |
| 20 | */ |
| 21 | public ?object $block = null; |
| 22 | |
| 23 | /** |
| 24 | * Block HTML. |
| 25 | * |
| 26 | * @var string |
| 27 | */ |
| 28 | public string $block_html = ''; |
| 29 | |
| 30 | /** |
| 31 | * Constructor |
| 32 | * |
| 33 | * @param array $attributes Attributes. |
| 34 | * @param object $block Block. |
| 35 | */ |
| 36 | public function __construct( $attributes = array(), $block = null ) { |
| 37 | $this->attributes = $attributes; |
| 38 | $this->block = $block; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Render the price name. |
| 43 | * |
| 44 | * @return void |
| 45 | */ |
| 46 | public function renderPriceName() { |
| 47 | $this->block_html .= '<!-- wp:surecart/price-name {"style":{"layout":{"selfStretch":"fixed","flexSize":"50%"},"typography":{"fontStyle":"normal","fontWeight":"600"}}} /-->'; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Render the price amount, trial and setup fee. |
| 52 | * |
| 53 | * @return void |
| 54 | */ |
| 55 | public function renderPriceAmountScratchAmountTrialAndSetupFee() { |
| 56 | $text_color = $this->attributes['textColor'] ?? '#8a8a8a'; |
| 57 | $this->block_html .= '<!-- wp:group {"style":{"spacing":{"blockGap":"0px"},"layout":{"selfStretch":"fixed","flexSize":"50%"}},"layout":{"type":"flex","orientation":"vertical","justifyContent":"right"}} -->'; |
| 58 | $this->block_html .= '<div class="wp-block-group">'; |
| 59 | $this->block_html .= '<!-- wp:group {"style":{"spacing":{"blockGap":"0.5rem"}},"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"left"}} -->'; |
| 60 | $this->block_html .= '<div class="wp-block-group">'; |
| 61 | $this->block_html .= '<!-- wp:surecart/price-scratch-amount {"style":{"typography":{"textDecoration":"line-through"}},"color":{"text":"#686868"}} /-->'; |
| 62 | $this->block_html .= '<!-- wp:surecart/price-amount {"style":{"typography":{"fontStyle":"normal","fontWeight":"700"}}} /-->'; |
| 63 | $this->block_html .= '<!-- wp:surecart/price-interval {"style":{"typography":{"fontStyle":"normal","fontWeight":"700"}}} /-->'; |
| 64 | $this->block_html .= '</div>'; |
| 65 | $this->block_html .= '<!-- /wp:group -->'; |
| 66 | $this->block_html .= '<!-- wp:surecart/price-trial {"style":{"color":{"text":"' . $text_color . '"},"elements":{"link":{"color":{"text":"' . $text_color . '"}}}},"fontSize":"small"} /-->'; |
| 67 | $this->block_html .= '<!-- wp:surecart/price-setup-fee {"style":{"color":{"text":"' . $text_color . '"},"elements":{"link":{"color":{"text":"' . $text_color . '"}}}},"fontSize":"small"} /-->'; |
| 68 | $this->block_html .= '</div>'; |
| 69 | $this->block_html .= '<!-- /wp:group -->'; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Render the price choices. |
| 74 | * |
| 75 | * @return void |
| 76 | */ |
| 77 | public function renderPriceChoices() { |
| 78 | $choices_attributes = array( |
| 79 | 'label' => $this->attributes['label'] ?? __( 'Pricing', 'surecart' ), |
| 80 | ); |
| 81 | |
| 82 | $template_attributes = array( |
| 83 | 'layout' => [ |
| 84 | 'type' => 'flex', |
| 85 | 'justifyContent' => 'left', |
| 86 | 'flexWrap' => 'nowrap', |
| 87 | 'orientation' => 'horizontal', |
| 88 | ], |
| 89 | 'textColor' => $this->attributes['textColor'] ?? 'black', |
| 90 | 'backgroundColor' => $this->attributes['backgroundColor'] ?? 'white', |
| 91 | 'style' => $this->attributes['style'] ?? [], |
| 92 | ); |
| 93 | |
| 94 | $this->block_html .= '<!-- wp:surecart/product-price-chooser ' . wp_json_encode( $choices_attributes ) . ' -->'; |
| 95 | $this->block_html .= '<!-- wp:surecart/product-price-choice-template ' . wp_json_encode( $template_attributes ) . ' -->'; |
| 96 | $this->renderPriceName(); |
| 97 | if ( $this->attributes['show_price'] ) { |
| 98 | $this->renderPriceAmountScratchAmountTrialAndSetupFee(); |
| 99 | } |
| 100 | $this->block_html .= '<!-- /wp:surecart/product-price-choice-template -->'; |
| 101 | $this->block_html .= '<!-- /wp:surecart/product-price-chooser -->'; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Render blocks. |
| 106 | * |
| 107 | * @return string |
| 108 | */ |
| 109 | public function doBlocks() { |
| 110 | return do_blocks( $this->block_html ); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Render the product price choices. |
| 115 | * |
| 116 | * @return string |
| 117 | */ |
| 118 | public function render() { |
| 119 | $this->renderPriceChoices(); |
| 120 | return $this->doBlocks(); |
| 121 | } |
| 122 | } |
| 123 |