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 / MiniCartBlockEditor.php

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

120 lines 3.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\Api\Resource\FrontendResource\CartResource;
6 use FluentCart\App\Helpers\CartHelper;
7 use FluentCart\App\Helpers\Helper;
8 use FluentCart\App\Hooks\Cart\CartLoader;
9 use FluentCart\App\Models\Product;
10 use FluentCart\App\Models\ProductVariation;
11 use FluentCart\App\Modules\Templating\AssetLoader;
12 use FluentCart\App\Services\Renderer\CartDrawerRenderer;
13 use FluentCart\App\Services\Renderer\MiniCartRenderer;
14 use FluentCart\App\Services\Renderer\ProductRenderer;
15 use FluentCart\App\Services\Translations\TransStrings;
16 use FluentCart\Framework\Support\Arr;
17
18 class MiniCartBlockEditor extends BlockEditor
19 {
20 protected static string $editorName = 'mini-cart';
21
22
23
24 public function getScripts(): array
25 {
26 return [
27 [
28 'source' => 'admin/BlockEditor/Cart/MiniCartBlockEditor.jsx',
29 'dependencies' => ['wp-blocks', 'wp-components']
30 ]
31 ];
32 }
33
34 public function getStyles(): array
35 {
36 return [
37 'admin/BlockEditor/Cart/style/mini-cart-block-editor.scss'
38 ];
39 }
40
41
42 public function supports(): array
43 {
44 return [
45 'html' => false,
46 'typography' => [
47 'fontSize' => true,
48 'lineHeight' => true
49 ],
50 'spacing' => [
51 'margin' => true,
52 'padding' => true
53 ],
54 'color' => [
55 'text' => true,
56 'background' => true,
57 ],
58 '__experimentalBorder' => [
59 'color' => true,
60 'radius' => true,
61 'style' => true,
62 'width' => true,
63 ],
64 'shadow' => true
65 ];
66 }
67
68 public function localizeData(): array
69 {
70 return [
71 $this->getLocalizationKey() => [
72 'slug' => $this->slugPrefix,
73 'name' => static::getEditorName(),
74 'title' => __('Mini Cart', 'fluent-cart'),
75 'description' => __('Display a button for shoppers to quickly view their cart.', 'fluent-cart'),
76 'placeholder_image' => Helper::getProductPlaceholderUrl(),
77 ],
78 'fluent_cart_block_translation' => TransStrings::blockStrings(),
79 ];
80 }
81
82 public function render(array $shortCodeAttribute, $block = null)
83 {
84 (new CartLoader())->registerDependency();
85 AssetLoader::loadMiniCartAssets();
86
87 $itemCount = 0;
88 $cartData = [];
89
90 // Hide mini cart count during instant checkout to avoid confusion
91 if (!CartHelper::doingInstantCheckout()) {
92 $cart = CartHelper::getCart(null, false);
93 if ($cart) {
94 $cartData = $cart->cart_data ?? [];
95 }
96 }
97
98 $countMode = Arr::get($shortCodeAttribute, 'count_mode', 'distinct_products');
99
100 if ($countMode === 'total_quantity') {
101 foreach ($cartData as $item) {
102 $itemCount += (int) ($item['quantity'] ?? 1);
103 }
104 } else {
105 $itemCount = count($cartData);
106 }
107
108 $miniCartRenderer = new MiniCartRenderer($cartData, [
109 'item_count' => $itemCount,
110 'count_mode' => $countMode,
111 ]);
112
113 ob_start();
114 $miniCartRenderer->renderMiniCart($shortCodeAttribute);
115 return ob_get_clean();
116
117 }
118
119 }
120