PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.0
1.7.0 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 All 50 releases
fluent-cart / app / Hooks / Handlers / BlockEditors / PricingTableBlockEditor.php

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

128 lines 4.7 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\Framework\Support\Arr;
10
11 class PricingTableBlockEditor extends BlockEditor
12 {
13
14 protected static string $editorName = 'product-pricing-table';
15
16 public function getScripts(): array
17 {
18 if (!App::isDevMode()) {
19 return [];
20 }
21 return [
22 [
23 'source' => 'admin/BlockEditor/PricingTable/PricingTableBlockEditor.jsx',
24 'dependencies' => ['wp-blocks', 'wp-components']
25 ]
26 ];
27 }
28
29 public function getStyles(): array
30 {
31 return [
32 'admin/BlockEditor/PricingTable/style/pricing-table-block-editor.scss',
33 'admin/BlockEditor/Components/style/fct-global-block-editor.scss'
34 ];
35 }
36
37 public function localizeData(): array
38 {
39 return [
40 $this->getLocalizationKey() => [
41 'slug' => $this->slugPrefix,
42 'name' => static::getEditorName(),
43
44 'trans' => TransStrings::getShopAppBlockEditorString(),
45 'title' => __('Pricing Table', 'fluent-cart'),
46 ],
47 'fluent_cart_block_editor_asset' => [
48 'placeholder_image' => Helper::getProductPlaceholderUrl(),
49 ],
50 'fluent_cart_block_translation' => TransStrings::blockStrings()
51 ];
52 }
53
54
55 public function render(array $shortCodeAttribute, $block = null): string
56 {
57
58 $groupBy = Arr::get($shortCodeAttribute, 'group_by', 'repeat_interval');
59 $showCheckoutButton = Arr::get($shortCodeAttribute, 'show_checkout_button', true) !== false;
60 $showCartButton = Arr::get($shortCodeAttribute, 'show_cart_button', true) !== false;
61 $iconVisibility = Arr::get($shortCodeAttribute, 'iconVisibility', true) !== false;
62 $productPerRow = Arr::get($shortCodeAttribute, 'product_per_row', 0);
63
64 $buttonOptions = Arr::get($shortCodeAttribute, 'buttonOptions', []);
65 $checkoutButtonUrlParams = Arr::get($shortCodeAttribute, 'checkout_button_url_params', '');
66
67 $variants = Arr::get($shortCodeAttribute, 'variations', []);
68 $variants = is_array($variants) ? $variants : [];
69 $variantIds = implode(',', $variants);
70
71 $activeVariant = Arr::get($shortCodeAttribute, 'active_variant', []);
72 $activeVariant = is_array($activeVariant) ? $activeVariant : (is_object($activeVariant) ? (array)$activeVariant : []);
73
74 $badge = Arr::get($shortCodeAttribute, 'badge', []);
75
76 $colors = Arr::get($shortCodeAttribute, 'colors', []);
77
78 // Initialize an empty array to store the formatted color strings
79 $colorStrings = [];
80
81 // Iterate over each color group (e.g., badgeColors, cardColors)
82 foreach ($colors as $colorGroup) {
83 // Iterate over each color within the color group
84 foreach ($colorGroup as $key => $color) {
85 // Append each color key and its value to the $colorStrings array
86 $colorStrings[] = $key . '=' . $color['value'];
87 }
88 }
89
90 // Implode the array into a comma-separated string
91 $allColorStrings = implode(', ', $colorStrings);
92
93 $badgeString = $this->assocArrayToString($badge);
94 $activeVariantString = $this->assocArrayToString($activeVariant);
95 $buttonOptionStrings = $this->assocArrayToString($buttonOptions);
96
97
98 $activeTab = Arr::get($shortCodeAttribute, 'active_tab', 0);
99
100 return PricingTableShortCode::make([
101 'variant_ids' => $variantIds,
102 'show_cart_button' => (string) $showCartButton,
103 'show_checkout_button' => (string) $showCheckoutButton,
104 'group_by' => $groupBy,
105 'active_tab' => $activeTab,
106 'active_variant' => $activeVariantString,
107 'badge' => $badgeString,
108 'colors' => $allColorStrings,
109 'product_per_row' => $productPerRow,
110 'button_options' => $buttonOptionStrings,
111 'url_params' => $checkoutButtonUrlParams,
112 'icon_visibility' => (string) $iconVisibility,
113 ])->renderShortcode($block);
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