PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.3
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.3
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 / BlockEditors / BuySectionBlockEditor.php

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

83 lines 2.7 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\App\Modules\Templating\AssetLoader;
6 use FluentCart\App\Services\Renderer\ProductRenderer;
7 use FluentCart\App\Services\Translations\TransStrings;
8 use FluentCart\App\Vite;
9 use FluentCart\Framework\Support\Arr;
10 use FluentCart\App\Models\Product;
11 use FluentCart\App\Helpers\Helper;
12 use FluentCart\App\App;
13 use FluentCart\Api\StoreSettings;
14
15 class BuySectionBlockEditor extends BlockEditor
16 {
17 protected static string $editorName = 'buy-section';
18
19 public function getScripts(): array
20 {
21 return [
22 [
23 'source' => 'admin/BlockEditor/BuySection/BuySectionBlockEditor.jsx',
24 'dependencies' => ['wp-blocks', 'wp-components']
25 ]
26 ];
27 }
28
29 public function getStyles(): array
30 {
31 return [
32 'admin/BlockEditor/BuySection/style/buy-section-block-editor.scss'
33 ];
34 }
35
36 public function localizeData(): array
37 {
38 return [
39 $this->getLocalizationKey() => [
40 'slug' => $this->slugPrefix,
41 'name' => static::getEditorName(),
42 'title' => __('Buy Section', 'fluent-cart'),
43 'description' => __('This block will display the buy section.', 'fluent-cart'),
44 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg'),
45 ],
46 'fluent_cart_block_translation' => TransStrings::blockStrings(),
47 ];
48 }
49
50 public function render(array $shortCodeAttribute, $block = null)
51 {
52 AssetLoader::loadSingleProductAssets();
53 $product = null;
54 $insideProductInfo = Arr::get($shortCodeAttribute, 'inside_product_info', 'no');
55 $queryType = Arr::get($shortCodeAttribute, 'query_type', 'default');
56
57 if ($insideProductInfo === 'yes' || $queryType === 'default') {
58 $product = fluent_cart_get_current_product();
59 } else {
60 $productId = Arr::get($shortCodeAttribute, 'product_id', false);
61 if ($productId) {
62 $product = Product::query()->with(['variants'])->find($productId);
63 }
64 }
65
66
67
68 if (!$product) {
69 return '';
70 }
71
72 // The Buy Section renders the single-product purchase UI, including
73 // Pro's advanced-variation selector — fire the asset hook so Pro
74 // enqueues the selector CSS/JS (without it the selector is unstyled and
75 // its price/variant JS never wires up). Pro dedupes by enqueue handle.
76 do_action('fluent_cart/advanced_variation/enqueue_assets');
77
78 ob_start();
79 (new ProductRenderer($product))->renderBuySection();
80 return ob_get_clean();
81 }
82 }
83