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

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

99 lines 2.8 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\Helpers\Helper;
6 use FluentCart\App\Models\Product;
7 use FluentCart\App\Services\Renderer\ProductRenderer;
8 use FluentCart\App\Services\Translations\TransStrings;
9 use FluentCart\Framework\Support\Arr;
10
11 class StockBlock extends BlockEditor
12 {
13 protected static string $editorName = 'stock';
14
15 public function supports(): array
16 {
17 return [
18 'html' => false,
19 'align' => ['left', 'center', 'right'],
20 'typography' => [
21 'fontSize' => true,
22 'lineHeight' => true
23 ],
24 'spacing' => [
25 'margin' => true
26 ],
27 'color' => [
28 'text' => true,
29 ]
30 ];
31 }
32
33 public function getScripts(): array
34 {
35 return [
36 [
37 'source' => 'admin/BlockEditor/Stock/StockBlock.jsx',
38 'dependencies' => ['wp-blocks', 'wp-components', 'wp-data', 'wp-block-editor', 'wp-element']
39 ]
40 ];
41 }
42
43 public function getStyles(): array
44 {
45 // 'admin/BlockEditor/Stock/style/stock-block-editor.scss'
46 return [];
47 }
48
49
50 public function localizeData(): array
51 {
52 return [
53 $this->getLocalizationKey() => [
54 'slug' => $this->slugPrefix,
55 'name' => static::getEditorName(),
56 'title' => __('Stock', 'fluent-cart'),
57 'description' => __('This block will display the stock.', 'fluent-cart'),
58 'placeholder_image' => Helper::getProductPlaceholderUrl(),
59 'supports' => $this->supports()
60 ],
61 'fluent_cart_block_translation' => TransStrings::blockStrings(),
62 ];
63 }
64
65 public function render(array $shortCodeAttribute, $block = null)
66 {
67 $product = null;
68 $insideProductInfo = Arr::get($shortCodeAttribute, 'inside_product_info', 'no');
69 $queryType = Arr::get($shortCodeAttribute, 'query_type', 'default');
70
71 if ($insideProductInfo === 'yes' || $queryType === 'default') {
72 $product = fluent_cart_get_current_product();
73
74 } else {
75 $productId = Arr::get($shortCodeAttribute, 'product_id', false);
76 if ($productId) {
77 $product = Product::query()->with(['variants'])->find($productId);
78 }
79 }
80
81 if (!$product) {
82 return '';
83 }
84
85 $wrapper_attributes = get_block_wrapper_attributes(
86 [
87 'class' => 'fct-product-stock wc-block-grid__product-stock',
88 ]
89 );
90
91 ob_start();
92 (new ProductRenderer($product))
93 ->renderStockAvailability($wrapper_attributes);
94
95 return ob_get_clean();
96 }
97
98 }
99