PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.4
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 / MiniCartBlockEditor.php

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

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