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 / ProductInfoBlockEditor.php

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

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