PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.27
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.27
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 / ProductInfoBlockEditor.php

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

103 lines 3.2 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\Hooks\Handlers\ShortCodes\ProductCardShortCode;
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 use FluentCart\App\Modules\Templating\AssetLoader;
15
16 class ProductInfoBlockEditor extends BlockEditor
17 {
18 protected static string $editorName = 'product-info';
19
20 public function getScripts(): array
21 {
22 return [
23 [
24 'source' => 'admin/BlockEditor/ProductInfo/ProductInfoBlockEditor.jsx',
25 'dependencies' => ['wp-blocks', 'wp-components']
26 ]
27 ];
28 }
29
30 public function getStyles(): array
31 {
32 return [
33 'admin/BlockEditor/ProductInfo/style/product-info-block-editor.scss'
34 ];
35 }
36
37 public function localizeData(): array
38 {
39 return [
40 $this->getLocalizationKey() => [
41 'slug' => $this->slugPrefix,
42 'name' => static::getEditorName(),
43 'title' => __('Product Info', 'fluent-cart'),
44 'description' => __('This block will display the product information.', 'fluent-cart'),
45 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg'),
46 ],
47 'fluent_cart_block_translation' => TransStrings::blockStrings(),
48 ];
49 }
50
51
52 protected function skipInnerBlocks(): bool
53 {
54 return true;
55 }
56
57 public function render(array $shortCodeAttribute, $block = null)
58 {
59 AssetLoader::loadSingleProductAssets();
60 AssetLoader::enqueueProductInfoFrontendStyles();
61
62 $queryType = Arr::get($shortCodeAttribute, 'query_type', 'default');
63 $product = null;
64 if ($queryType === 'default') {
65 $product = fluent_cart_get_current_product();
66 $product && setup_postdata($product->ID);
67 } else {
68 $productId = Arr::get($shortCodeAttribute, 'product_id', false);
69 if ($productId) {
70 $product = Product::query()->with(['detail', 'variants'])->find($productId);
71 if ($product) {
72 setup_postdata($product->ID);
73 }
74 }
75 }
76
77 if (!$product) {
78 return '';
79 }
80
81 $innerBlocksContent = '';
82 if ($block instanceof \WP_Block && !empty($block->inner_blocks)) {
83 $innerBlocksContent .= '<div class="product-info-block-wrapper">';
84 foreach ($block->inner_blocks as $inner_block) {
85 if (isset($inner_block->parsed_block)) {
86 $innerBlocksContent .= '<div class="product-info-child-block">';
87 $innerBlocksContent .= $inner_block->render();
88 $innerBlocksContent .= '</div>';
89 }
90 }
91 $innerBlocksContent .= '</div>';
92 }
93
94 if ($queryType === 'custom') {
95 wp_reset_postdata();
96 }
97
98 return $innerBlocksContent;
99 }
100
101
102 }
103