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

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

135 lines 4.4 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\ProductCardRender;
7 use FluentCart\App\Services\Renderer\ProductRenderer;
8 use FluentCart\App\Services\Translations\TransStrings;
9 use FluentCart\App\Vite;
10 use FluentCart\Framework\Support\Arr;
11 use FluentCart\App\Models\Product;
12
13 class ProductTitleBlockEditor extends BlockEditor
14 {
15 protected static string $editorName = 'product-title';
16
17 public function ancestor(): array
18 {
19 return [
20 'fluent-cart/products',
21 'fluent-cart/product-carousel',
22 'fluent-cart/product-info',
23 'fluent-cart/related-product',
24 ];
25 }
26
27 public function supports(): array
28 {
29 return [
30 'html' => false,
31 'align' => true,
32 'typography' => [
33 'fontSize' => true,
34 'lineHeight' => true,
35 '__experimentalFontFamily' => true,
36 '__experimentalFontWeight' => true,
37 '__experimentalFontStyle' => true,
38 '__experimentalTextTransform' => true,
39 '__experimentalTextDecoration' => true,
40 '__experimentalLetterSpacing' => true,
41 '__experimentalDefaultControls' => [
42 'fontSize' => true,
43 'lineHeight' => true,
44 'fontWeight' => true,
45 ],
46 ],
47 'color' => [
48 'text' => true,
49 'background' => true,
50 'link' => true,
51 'gradients' => true,
52 ],
53 'spacing' => [
54 'margin' => true,
55 'padding' => true,
56 ],
57 '__experimentalBorder' => [
58 'color' => true,
59 'radius' => true,
60 'style' => true,
61 'width' => true,
62 ],
63 'shadow' => true,
64 ];
65 }
66
67 public function getScripts(): array
68 {
69 return [
70 [
71 'source' => 'admin/BlockEditor/ProductTitle/ProductTitleBlockEditor.jsx',
72 'dependencies' => ['wp-blocks', 'wp-components']
73 ]
74 ];
75 }
76
77 public function getStyles(): array
78 {
79 return [
80 'admin/BlockEditor/ProductTitle/style/product-title-block-editor.scss'
81 ];
82 }
83
84 public function localizeData(): array
85 {
86 return [
87 $this->getLocalizationKey() => [
88 'slug' => $this->slugPrefix,
89 'name' => static::getEditorName(),
90 'title' => __('Product Title', 'fluent-cart'),
91 'description' => __('This block will display the product title.', 'fluent-cart'),
92 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg')
93 ],
94 'fluent_cart_block_translation' => TransStrings::blockStrings(),
95 ];
96 }
97
98 public function render(array $shortCodeAttribute, $block = null)
99 {
100 AssetLoader::loadSingleProductAssets();
101 $product = null;
102 $insideProductInfo = Arr::get($shortCodeAttribute, 'inside_product_info', 'no');
103 $queryType = Arr::get($shortCodeAttribute, 'query_type', 'default');
104
105 if ($insideProductInfo === 'yes' || $queryType === 'default') {
106 $product = fluent_cart_get_current_product();
107 }
108
109 if (!$product) {
110 $productId = Arr::get($shortCodeAttribute, 'product_id', false);
111 if ($productId) {
112 $product = Product::query()->with(['detail', 'variants'])->find($productId);
113 }
114 }
115
116 if (!$product) {
117 return '';
118 }
119
120 $isLink = Arr::get($shortCodeAttribute, 'isLink', true);
121 $target = Arr::get($shortCodeAttribute, 'linkTarget', '_self');
122
123 $wrapper_attributes = get_block_wrapper_attributes([
124 'class' => 'fct-product-card-title wc-block-grid__product-title',
125 ]);
126
127 ob_start();
128 (new ProductCardRender($product))->renderTitle($wrapper_attributes, [
129 'isLink' => $isLink,
130 'target' => $target,
131 ]);
132 return ob_get_clean();
133 }
134 }
135