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

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

84 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\CurrenciesHelper;
6 use FluentCart\App\Hooks\Handlers\ShortCodes\ProductCardShortCode;
7 use FluentCart\App\Models\Product;
8 use FluentCart\App\Services\Translations\TransStrings;
9 use FluentCart\Framework\Support\Arr;
10 use FluentCart\App\Helpers\Helper;
11
12 class ProductCardBlockEditor extends BlockEditor
13 {
14 protected static string $editorName = 'product-card';
15
16 public function getScripts(): array
17 {
18 return [
19 [
20 'source' => 'admin/BlockEditor/ProductCard/ProductCardBlockEditor.jsx',
21 'dependencies' => ['wp-blocks', 'wp-components']
22 ]
23 ];
24 }
25
26 public function getStyles(): array
27 {
28 return ['admin/BlockEditor/ProductCard/style/product-card-block-editor.scss'];
29 }
30
31 public function localizeData(): array
32 {
33 $currencyCode = Helper::shopConfig('currency');
34 $currencySign = CurrenciesHelper::getCurrencySign($currencyCode);
35 $currencyPosition = Helper::shopConfig('currency_position');
36
37 return [
38 $this->getLocalizationKey() => [
39 'slug' => $this->slugPrefix,
40 'name' => static::getEditorName(),
41 'title' => __('Product Card', 'fluent-cart'),
42 'description' => __('This block will display the product card.', 'fluent-cart'),
43 'placeholder_image' => Helper::getProductPlaceholderUrl(),
44 'currency_sign' => $currencySign,
45 'currency_position' => $currencyPosition
46 ],
47 'fluent_cart_block_translation' => TransStrings::blockStrings(),
48 ];
49 }
50
51 public function render(array $shortCodeAttribute, $block = null): string
52 {
53 $queryType = Arr::get($shortCodeAttribute, 'query_type', 'default');
54
55 $product = null;
56 if ($queryType === 'default') {
57 $product = fluent_cart_get_current_product();
58 // TODO: Check
59 //$product && setup_postdata($product->ID);
60 } else {
61 if ($productId = Arr::get($shortCodeAttribute, 'product_id', false)) {
62 $product = Product::query()->with(['variants'])->find($productId);
63 if ($product) {
64 setup_postdata($product->ID);
65 }
66 }
67 }
68
69 if (!$product) {
70 return '';
71 }
72
73 return ProductCardShortCode::make([
74 'product_id' => $product->ID,
75 'variant_id' => Arr::get($shortCodeAttribute, 'variant_id', ''),
76 'price_format' => Arr::get($shortCodeAttribute, 'price_format', 'starts_from'),
77 'card_width' => Arr::get($shortCodeAttribute, 'card_width', 216),
78 ])->renderShortcode($block);
79 }
80
81
82
83 }
84