fluent-cart
/
app
/
Hooks
/
Handlers
/
BlockEditors
/
ProductCarousel
/
ProductCarouselBlockEditor.php
ProductCarouselBlockEditor.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.2, at app/Hooks/Handlers/BlockEditors/ProductCarousel/ProductCarouselBlockEditor.php
| 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 | // The carousel renders card parts via individual ProductCardRender |
| 103 | // methods (renderTitle/renderPrices/…), not ProductCardRender::render(), |
| 104 | // so the renderer's hook never fires here. Fire the advanced-variation |
| 105 | // asset hook once at the block level — same no-arg, fire-once contract |
| 106 | // as the Related Products block — so Pro's selector assets load. |
| 107 | do_action('fluent_cart/advanced_variation/enqueue_assets'); |
| 108 | |
| 109 | $app = fluentCart(); |
| 110 | $slug = $app->config->get('app.slug'); |
| 111 | |
| 112 | Vite::enqueueStaticScript( |
| 113 | $slug . '-fluentcart-swiper-js', |
| 114 | 'public/lib/swiper/swiper-bundle.min.js', |
| 115 | [$slug . '-app',] |
| 116 | ); |
| 117 | |
| 118 | Vite::enqueueStaticStyle( |
| 119 | $slug . '-fluentcart-swiper-css', |
| 120 | 'public/lib/swiper/swiper-bundle.min.css', |
| 121 | ); |
| 122 | |
| 123 | Vite::enqueueStyle( |
| 124 | 'fluentcart-product-carousel', |
| 125 | 'public/carousel/products/style/product-carousel.scss', |
| 126 | ); |
| 127 | |
| 128 | Vite::enqueueScript( |
| 129 | 'fluentcart-product-carousel', |
| 130 | 'public/carousel/products/product-carousel.js', |
| 131 | [] |
| 132 | ); |
| 133 | |
| 134 | return $content; |
| 135 | } |
| 136 | } |
| 137 |