PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.25
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.25
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 / ShortCodes / MiniCartShortcode.php

MiniCartShortcode.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.25, at app/Hooks/Handlers/ShortCodes/MiniCartShortcode.php

57 lines 1.6 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\ShortCodes;
4
5 use FluentCart\Api\Resource\FrontendResource\CartResource;
6 use FluentCart\App\Helpers\CartHelper;
7 use FluentCart\App\Hooks\Cart\CartLoader;
8 use FluentCart\App\Hooks\Handlers\ShortCodes\ShortCode;
9 use FluentCart\App\Helpers\Helper;
10 use FluentCart\App\Models\Product;
11 use FluentCart\App\Models\ProductVariation;
12 use FluentCart\App\Modules\Templating\AssetLoader;
13 use FluentCart\App\Services\Renderer\CartDrawerRenderer;
14 use FluentCart\App\Services\Renderer\MiniCartRenderer;
15 use FluentCart\App\Services\Renderer\ProductRenderer;
16 use FluentCart\Framework\Support\Arr;
17
18 class MiniCartShortcode extends ShortCode
19 {
20 protected static string $shortCodeName = 'fluent_cart_mini_cart';
21
22 public function getStyles(): array
23 {
24 return [
25 'public/cart-drawer/mini-cart.scss',
26 ];
27 }
28
29
30 public function render(?array $viewData = null)
31 {
32 $data = $viewData ?? $this->shortCodeAttributes ?? [];
33
34 (new CartLoader())->registerDependency();
35 $itemCount = 0;
36 $cartData = [];
37
38 // Hide mini cart count during instant checkout to avoid confusion
39 if (!CartHelper::doingInstantCheckout()) {
40 $cart = CartHelper::getCart(null, false);
41 if ($cart) {
42 $cartData = $cart->cart_data ?? [];
43 $itemCount = count($cartData);
44 }
45 }
46
47 $miniCartRenderer = new MiniCartRenderer($cartData, [
48 'item_count' => $itemCount
49 ]);
50
51 $data['is_shortcode'] = true;
52
53 $miniCartRenderer->renderMiniCart($data);
54 }
55 }
56
57