PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.0
1.7.0 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 All 50 releases
fluent-cart / app / Hooks / Handlers / BlockEditors / BuySectionBlockEditor.php

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

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