PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.2.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.2.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / BlockLibrary / ProductVariantsMigrationService.php
ProductVariantsMigrationService.php
94 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\BlockLibrary;
4
5 /**
6 * Provide the migration service for the product variant block.
7 */
8 class ProductVariantsMigrationService {
9 /**
10 * Attributes
11 *
12 * @var array
13 */
14 public $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 variant pill
43 */
44 public function renderVariantPill() {
45 $block_attributes = array_merge(
46 $this->attributes,
47 array(
48 'highlight_text' => '#ffffff',
49 'highlight_background' => '#000000',
50 'highlight_border' => '#000000',
51 )
52 );
53
54 // remove the margin since it is used for the parent block.
55 $block_attributes['style']['spacing'] = array(
56 'padding' => $block_attributes['style']['spacing']['padding'] ?? '',
57 );
58
59 $this->block_html .= '<!-- wp:surecart/product-variant-pill ' . wp_json_encode( $block_attributes ) . ' /-->';
60 }
61
62 /**
63 * Render the product variant block.
64 *
65 * @return void
66 */
67 public function renderProductVariants() {
68 $wrapper_attributes['style']['spacing']['margin'] = $this->attributes['style']['spacing']['margin'] ?? '';
69
70 $this->block_html = '<!-- wp:surecart/product-variant-pills ' . wp_json_encode( $wrapper_attributes ) . ' -->';
71 $this->renderVariantPill();
72 $this->block_html .= '<!-- /wp:surecart/product-variant-pills -->';
73 }
74
75 /**
76 * Render the blocks.
77 *
78 * @return string
79 */
80 public function doBlocks() {
81 return do_blocks( $this->block_html );
82 }
83
84 /**
85 * Render the new variants block.
86 *
87 * @return string
88 */
89 public function render() {
90 $this->renderProductVariants();
91 return $this->doBlocks();
92 }
93 }
94