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
ProductCollectionBadgesMigrationService.php
80 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\BlockLibrary; |
| 4 | |
| 5 | /** |
| 6 | * Provide the migration service for the product collection badges block. |
| 7 | */ |
| 8 | class ProductCollectionBadgesMigrationService { |
| 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 collection badges. |
| 43 | * |
| 44 | * @return void |
| 45 | */ |
| 46 | public function renderProductCollectionBadges() { |
| 47 | $layout_attributes = array( |
| 48 | 'count' => $this->attributes['count'] ?? 1, |
| 49 | 'style' => array( |
| 50 | 'spacing' => array( |
| 51 | 'blockGap' => $this->attributes['style']['spacing']['blockGap'] ?? '3px', |
| 52 | ), |
| 53 | ), |
| 54 | ); |
| 55 | |
| 56 | $this->block_html = '<!-- wp:surecart/product-collection-tags ' . wp_json_encode( $layout_attributes ) . ' -->'; |
| 57 | $this->block_html .= '<!-- wp:surecart/product-collection-tag ' . wp_json_encode( $this->attributes ) . ' /-->'; |
| 58 | $this->block_html .= '<!-- /wp:surecart/product-collection-tags -->'; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Render blocks. |
| 63 | * |
| 64 | * @return string |
| 65 | */ |
| 66 | public function doBlocks() { |
| 67 | return do_blocks( $this->block_html ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Render the new product collection badges. |
| 72 | * |
| 73 | * @return string |
| 74 | */ |
| 75 | public function render() { |
| 76 | $this->renderProductCollectionBadges(); |
| 77 | return $this->doBlocks(); |
| 78 | } |
| 79 | } |
| 80 |