PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.19
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.19
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Hooks / Handlers / BlockEditors / PricingTableBlockEditor.php

PricingTableBlockEditor.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.19, at app/Hooks/Handlers/BlockEditors/PricingTableBlockEditor.php

128 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Hooks\Handlers\BlockEditors;
4
5 use FluentCart\App\App;
6 use FluentCart\App\Helpers\Helper;
7 use FluentCart\App\Hooks\Handlers\ShortCodes\PricingTableShortCode;
8 use FluentCart\App\Services\Translations\TransStrings;
9 use FluentCart\App\Vite;
10 use FluentCart\Framework\Support\Arr;
11
12 class PricingTableBlockEditor extends BlockEditor
13 {
14
15 protected static string $editorName = 'product-pricing-table';
16
17 public function getScripts(): array
18 {
19 if (!App::isDevMode()) {
20 return [];
21 }
22 return [
23 [
24 'source' => 'admin/BlockEditor/PricingTable/PricingTableBlockEditor.jsx',
25 'dependencies' => ['wp-blocks', 'wp-components']
26 ]
27 ];
28 }
29
30 public function getStyles(): array
31 {
32 return ['admin/BlockEditor/PricingTable/style/pricing-table-block-editor.scss'];
33 }
34
35 public function localizeData(): array
36 {
37 return [
38 $this->getLocalizationKey() => [
39 'slug' => $this->slugPrefix,
40 'name' => static::getEditorName(),
41
42 'trans' => TransStrings::getShopAppBlockEditorString(),
43 'title' => __('Pricing Table', 'fluent-cart'),
44 ],
45 'fluent_cart_block_editor_asset' => [
46 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg'),
47 ],
48 'fluent_cart_block_translation' => TransStrings::blockStrings()
49 ];
50 }
51
52
53 public function render(array $shortCodeAttribute, $block = null): string
54 {
55
56 $groupBy = Arr::get($shortCodeAttribute, 'group_by', 'repeat_interval');
57 $showCheckoutButton = Arr::get($shortCodeAttribute, 'show_checkout_button', true) !== false;
58 $showCartButton = Arr::get($shortCodeAttribute, 'show_cart_button', true) !== false;
59 $iconVisibility = Arr::get($shortCodeAttribute, 'iconVisibility', true) !== false;
60 $productPerRow = Arr::get($shortCodeAttribute, 'product_per_row', 0);
61
62 $buttonOptions = Arr::get($shortCodeAttribute, 'buttonOptions', []);
63 $checkoutButtonUrlParams = Arr::get($shortCodeAttribute, 'checkout_button_url_params', '');
64
65 $variants = Arr::get($shortCodeAttribute, 'variations', []);
66 $variants = is_array($variants) ? $variants : [];
67 $variantIds = implode(',', $variants);
68
69 $activeVariant = Arr::get($shortCodeAttribute, 'active_variant', []);
70 $activeVariant = is_array($activeVariant) ? $activeVariant : (is_object($activeVariant) ? (array)$activeVariant : []);
71
72 $badge = Arr::get($shortCodeAttribute, 'badge', []);
73
74 $colors = Arr::get($shortCodeAttribute, 'colors', []);
75
76 // Initialize an empty array to store the formatted color strings
77 $colorStrings = [];
78
79 // Iterate over each color group (e.g., badgeColors, cardColors)
80 foreach ($colors as $colorGroup) {
81 // Iterate over each color within the color group
82 foreach ($colorGroup as $key => $color) {
83 // Append each color key and its value to the $colorStrings array
84 $colorStrings[] = $key . '=' . $color['value'];
85 }
86 }
87
88 // Implode the array into a comma-separated string
89 $allColorStrings = implode(', ', $colorStrings);
90
91 $badgeString = $this->assocArrayToString($badge);
92 $activeVariantString = $this->assocArrayToString($activeVariant);
93 $buttonOptionStrings = $this->assocArrayToString($buttonOptions);
94
95
96 $activeTab = Arr::get($shortCodeAttribute, 'active_tab', 0);
97
98 $code = "[" . PricingTableShortCode::SHORT_CODE .
99 " variant_ids='{$variantIds}'" .
100 " show_cart_button='{$showCartButton}'" .
101 " show_checkout_button='{$showCheckoutButton}'" .
102 " group_by='{$groupBy}'" .
103 " active_tab='{$activeTab}'" .
104 " active_variant='{$activeVariantString}'" .
105 " badge='{$badgeString}'" .
106 " colors='{$allColorStrings}'" .
107 " product_per_row='{$productPerRow}'" .
108 " button_options='{$buttonOptionStrings}'" .
109 " url_params='$checkoutButtonUrlParams'".
110 " icon_visibility='{$iconVisibility}'" .
111 " ]";
112
113 return $code;
114 }
115
116 private function assocArrayToString(array $array, string $delimiter = ', '): string
117 {
118 return implode($delimiter, array_map(
119 function ($key, $value) {
120 return $key . '=' . $value;
121 },
122 array_keys($array),
123 $array
124 ));
125 }
126
127 }
128