PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.4.2
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.4.2
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 1.3.19 All 49 releases
fluent-cart / app / Hooks / Handlers / BlockEditors / ProductCarousel / ProductCarouselBlockEditor.php

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

130 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\ProductCarousel;
4
5 use FluentCart\App\Helpers\Helper;
6 use FluentCart\App\Hooks\Handlers\BlockEditors\BlockEditor;
7 use FluentCart\App\Hooks\Handlers\BlockEditors\ProductCarousel\InnerBlocks\InnerBlocks;
8 use FluentCart\App\Hooks\Handlers\ShortCodes\ShopAppHandler;
9 use FluentCart\App\Modules\Templating\AssetLoader;
10 use FluentCart\App\Services\Translations\TransStrings;
11 use FluentCart\App\Vite;
12 use FluentCart\Framework\Support\Arr;
13
14 class ProductCarouselBlockEditor extends BlockEditor
15 {
16 protected static string $editorName = 'product-carousel';
17
18 protected ?string $localizationKey = 'fluent_cart_product_carousel_block_editor_data';
19
20 public function getScripts(): array
21 {
22 return [
23 [
24 'source' => 'admin/BlockEditor/ProductCarousel/ProductCarouselBlockEditor.jsx',
25 'dependencies' => [
26 'wp-blocks',
27 'wp-components',
28 'wp-block-editor',
29 'wp-data',
30 'wp-element',
31 ]
32 ]
33 ];
34 }
35
36 public function getStyles(): array
37 {
38 return [
39 'admin/BlockEditor/ShopApp/style/shop-app-block-editor.css',
40 'admin/BlockEditor/ProductInfo/style/product-info-block-editor.scss',
41 'admin/BlockEditor/ProductCarousel/style/product-carousel-block-editor.scss'
42 ];
43 }
44
45 public function init(): void
46 {
47 parent::init();
48
49 $this->registerInnerBlocks();
50 }
51
52 public function registerInnerBlocks()
53 {
54 InnerBlocks::register();
55 }
56
57 public function localizeData(): array
58 {
59 return [
60 $this->getLocalizationKey() => [
61 'rest' => Helper::getRestInfo(),
62 'slug' => $this->slugPrefix,
63 'name' => static::getEditorName(),
64 'trans' => TransStrings::getShopAppBlockEditorString(),
65 'title' => __('Product Carousel', 'fluent-cart'),
66 'description' => __('This block will display the product carousel.', 'fluent-cart'),
67 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg')
68 ],
69 'fluent_cart_block_editor_asset' => [
70 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg'),
71 ],
72 'fluent_cart_block_translation' => TransStrings::blockStrings(),
73 'fluentCartCarouselVars' => [
74 'defaultSlides' => 3,
75 'spaceBetween' => 16,
76 'breakpoints' => [
77 0 => ['slidesPerView' => 1],
78 768 => ['slidesPerView' => 2],
79 1024 => ['slidesPerView' => 3],
80 1280 => ['slidesPerView' => 4],
81 ],
82 'rtl' => is_rtl(),
83 ],
84 ];
85 }
86
87 public function provideContext(): array
88 {
89 // in which name the data will be received => which attr
90 return [
91 'fluent-cart/carousel_settings' => 'carousel_settings',
92 'fluent-cart/product_ids' => 'product_ids',
93 'fluent-cart/has_controls' => 'has_controls',
94 'fluent-cart/has_pagination' => 'has_pagination',
95 ];
96 }
97
98 public function render(array $shortCodeAttribute, $block = null, $content = null): string
99 {
100 AssetLoader::loadProductArchiveAssets();
101
102 $app = fluentCart();
103 $slug = $app->config->get('app.slug');
104
105 Vite::enqueueStaticScript(
106 $slug . '-fluentcart-swiper-js',
107 'public/lib/swiper/swiper-bundle.min.js',
108 [$slug . '-app',]
109 );
110
111 Vite::enqueueStaticStyle(
112 $slug . '-fluentcart-swiper-css',
113 'public/lib/swiper/swiper-bundle.min.css',
114 );
115
116 Vite::enqueueStyle(
117 'fluentcart-product-carousel',
118 'public/carousel/products/style/product-carousel.scss',
119 );
120
121 Vite::enqueueScript(
122 'fluentcart-product-carousel',
123 'public/carousel/products/product-carousel.js',
124 []
125 );
126
127 return $content;
128 }
129 }
130