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 / ShopApp / ShopAppBlockEditor.php

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

123 lines 4.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\ShopApp;
4
5 use FluentCart\Api\Taxonomy;
6 use FluentCart\App\CPT\FluentProducts;
7 use FluentCart\App\Helpers\Helper;
8 use FluentCart\App\Hooks\Handlers\BlockEditors\BlockEditor;
9 use FluentCart\App\Hooks\Handlers\BlockEditors\ShopApp\InnerBlocks\InnerBlocks;
10 use FluentCart\App\Hooks\Handlers\ShortCodes\ShopAppHandler;
11 use FluentCart\App\Modules\Templating\AssetLoader;
12 use FluentCart\App\Services\Translations\TransStrings;
13 use FluentCart\Framework\Support\Arr;
14 use FluentCart\Framework\Support\Collection;
15 use FluentCart\Framework\Support\Str;
16
17 class ShopAppBlockEditor extends BlockEditor
18 {
19 protected static string $editorName = 'products';
20
21 protected ?string $localizationKey = 'fluent_cart_shop_app_block_editor_data';
22
23 public function getScripts(): array
24 {
25 return [
26 [
27 'source' => 'admin/BlockEditor/ShopApp/ShopAppBlockEditor.jsx',
28 'dependencies' => ['wp-blocks', 'wp-components']
29 ]
30 ];
31 }
32
33 public function getStyles(): array
34 {
35 return ['admin/BlockEditor/ShopApp/style/shop-app-block-editor.css'];
36 }
37
38 public function init(): void
39 {
40 parent::init();
41
42 $this->registerInnerBlocks();
43 }
44
45 public function registerInnerBlocks()
46 {
47 InnerBlocks::register();
48 }
49
50 public function localizeData(): array
51 {
52 $taxonomies = Taxonomy::getTaxonomies();
53
54 $taxonomies = Collection::make($taxonomies)
55 ->map(function ($taxonomy) {
56 return [
57 'name' => $taxonomy,
58 'label' => Str::headline($taxonomy),
59 'parent' => 0,
60 'terms' => Taxonomy::getFormattedTerms($taxonomy, false, null, 'value', 'label'),
61 ];
62 });
63
64 return [
65 $this->getLocalizationKey() => [
66 'rest' => Helper::getRestInfo(),
67 'slug' => $this->slugPrefix,
68 'name' => static::getEditorName(),
69 'product_categories' => $this->getMetaFilterOptions('categories'),
70 'trans' => TransStrings::getShopAppBlockEditorString(),
71 'taxonomies' => $taxonomies,
72 'title' => __('Products', 'fluent-cart'),
73 ],
74 'fluent_cart_block_editor_asset' => [
75 'placeholder_image' => Helper::getProductPlaceholderUrl(),
76 ],
77 'fluent_cart_block_translation' => TransStrings::blockStrings()
78 ];
79 }
80
81 private function getMetaFilterOptions($key): array
82 {
83 $options = get_categories([
84 'taxonomy' => 'product-' . $key,
85 'post_type' => FluentProducts::CPT_NAME
86 ]);
87
88 return Collection::make($options)->map(function ($meta) {
89 return [
90 'value' => $meta->term_id,
91 'label' => $meta->name,
92 ];
93 })->toArray();
94 }
95
96 public function provideContext(): array
97 {
98 // in which name the data will be received => which attr
99 return [
100 'fluent-cart/paginator' => 'paginator',
101 'fluent-cart/per_page' => 'per_page',
102 'fluent-cart/enable_filter' => 'enable_filter',
103 'fluent-cart/product_box_grid_size' => 'product_box_grid_size',
104 'fluent-cart/view_mode' => 'view_mode',
105 'fluent-cart/filters' => 'filters',
106 'fluent-cart/default_filters' => 'default_filters',
107 'fluent-cart/order_type' => 'order_type',
108 'fluent-cart/order_by' => 'order_by',
109 'fluent-cart/live_filter' => 'live_filter',
110 'fluent-cart/price_format' => 'price_format',
111 'fluent-cart/enable_wildcard_filter' => 'enable_wildcard_filter',
112
113 ];
114 }
115
116 public function render(array $shortCodeAttribute, $block = null, $content = null): string
117 {
118 AssetLoader::loadProductArchiveAssets();
119 do_action('fluent_cart/advanced_variation/enqueue_assets');
120 return $content;
121 }
122 }
123