PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.26
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.26
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 trunk All 48 releases
fluent-cart / app / Hooks / Handlers / ShortCodes / CartShortcode.php

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

62 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\CurrencySettings;
6 use FluentCart\Api\StoreSettings;
7 use FluentCart\App\App;
8 use FluentCart\App\Helpers\CartHelper;
9 use FluentCart\App\Hooks\Cart\CartLoader;
10 use FluentCart\App\Vite;
11 use FluentCart\Framework\Support\Arr;
12 use FluentCart\Api\Resource\FrontendResource\CartResource;
13 use FluentCart\App\Modules\Templating\AssetLoader;
14 use FluentCart\App\Services\Renderer\CartRenderer;
15
16 class CartShortcode extends ShortCode
17 {
18 const SHORT_CODE = 'fluent_cart_cart';
19 protected static string $shortCodeName = 'fluent_cart_cart';
20
21 public static function register()
22 {
23 parent::register();
24
25 add_action('wp_enqueue_scripts', function () {
26 $action = App::request()->get('action') ?? '';
27 if ($action === 'elementor') {
28 return;
29 }
30
31 if (has_shortcode(get_the_content(), static::SHORT_CODE) || has_block('fluent-cart/cart_cart')) {
32 (new static())->enqueueStyles();
33 }
34 }, 10);
35 }
36
37 public function render(?array $viewData = null)
38 {
39 AssetLoader::markFrontendAssetsRequired();
40 $storeSettings = new StoreSettings();
41 $cart = CartHelper::getCart();
42 $cartItems = $cart->cart_data ?? [];
43 $cartRenderer = new CartRenderer($cartItems);
44
45 if (!$cart || !$cart->cart_data) {
46 $cartRenderer->renderEmpty();
47 return;
48 }
49
50 $cart->reValidateCoupons();
51 $cartRenderer->render();
52 }
53
54 public function getStyles(): array
55 {
56 (new CartLoader())->enqueueStyle();
57
58 return [];
59 }
60
61 }
62