| 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')) { |
| 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 |
|