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

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

125 lines 4.1 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\Models\Product;
6 use FluentCart\App\Modules\Templating\AssetLoader;
7 use FluentCart\App\Services\Renderer\ProductCardRender;
8 use FluentCart\App\Services\Translations\TransStrings;
9 use FluentCart\Framework\Support\Arr;
10
11 class ProductPackageDescriptionBlockEditor extends BlockEditor
12 {
13 protected static string $editorName = 'product-package-description';
14
15 public function ancestor(): array
16 {
17 return [
18 'fluent-cart/product-info'
19 ];
20 }
21
22 public function supports(): array
23 {
24 return [
25 'html' => false,
26 'align' => ['left', 'center', 'right'],
27 'typography' => [
28 'fontSize' => true,
29 'lineHeight' => true,
30 '__experimentalFontFamily' => true,
31 '__experimentalFontWeight' => true,
32 '__experimentalFontStyle' => true,
33 '__experimentalTextTransform' => true,
34 '__experimentalLetterSpacing' => true,
35 '__experimentalDefaultControls' => [
36 'fontSize' => true,
37 ],
38 ],
39 'color' => [
40 'text' => true,
41 'background' => true,
42 ],
43 'spacing' => [
44 'margin' => true,
45 'padding' => true,
46 ],
47 '__experimentalBorder' => [
48 'color' => true,
49 'radius' => true,
50 'style' => true,
51 'width' => true,
52 ],
53 'shadow' => true,
54 ];
55 }
56
57 public function getScripts(): array
58 {
59 return [
60 [
61 'source' => 'admin/BlockEditor/ProductPackageDescription/ProductPackageDescriptionBlockEditor.jsx',
62 'dependencies' => ['wp-blocks', 'wp-components']
63 ]
64 ];
65 }
66
67 public function getStyles(): array
68 {
69 return [
70 'admin/BlockEditor/ProductPackageDescription/style/product-package-description-block-editor.scss'
71 ];
72 }
73
74 public function localizeData(): array
75 {
76 return [
77 $this->getLocalizationKey() => [
78 'slug' => $this->slugPrefix,
79 'name' => static::getEditorName(),
80 'title' => __('Product Package Description', 'fluent-cart'),
81 'description' => __('Displays the product packaging details (name, type, dimensions, weight).', 'fluent-cart'),
82 ],
83 'fluent_cart_block_translation' => TransStrings::blockStrings(),
84 ];
85 }
86
87 public function render(array $shortCodeAttribute, $block = null): string
88 {
89 AssetLoader::loadSingleProductAssets();
90 $product = fluent_cart_get_current_product();
91
92 if (!$product) {
93 $productId = Arr::get($shortCodeAttribute, 'product_id', false);
94 if ($productId) {
95 $product = Product::query()->with(['detail', 'variants'])->find($productId);
96 }
97 }
98
99 if (!$product) {
100 return '';
101 }
102
103 $showName = (bool) Arr::get($shortCodeAttribute, 'show_name', true);
104 $showDimensions = (bool) Arr::get($shortCodeAttribute, 'show_dimensions', true);
105 $showProductWeight = (bool) Arr::get($shortCodeAttribute, 'show_product_weight', true);
106 $showTotalWeight = (bool) Arr::get($shortCodeAttribute, 'show_total_weight', true);
107
108 $wrapper_attributes = get_block_wrapper_attributes([
109 'class' => 'fct-package-description',
110 'data-fluent-cart-package-description' => '',
111 ]);
112
113 ob_start();
114 (new ProductCardRender($product))->renderPackageDescription(
115 $wrapper_attributes,
116 $showName,
117 $showDimensions,
118 $showProductWeight,
119 $showTotalWeight
120 );
121
122 return ob_get_clean();
123 }
124 }
125