PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
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 trunk All 48 releases
fluent-cart / app / Hooks / Handlers / BlockEditors / Buttons / BuyNowButtonBlockEditor.php

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

127 lines 3.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\Buttons;
4
5 use FluentCart\Api\StoreSettings;
6 use FluentCart\App\Helpers\CartHelper;
7 use FluentCart\App\Helpers\Helper;
8 use FluentCart\App\Hooks\Cart\WebCheckoutHandler;
9 use FluentCart\App\Hooks\Handlers\BlockEditors\BlockEditor;
10 use FluentCart\App\Http\Routes\WebRoutes;
11 use FluentCart\App\Models\Cart;
12 use FluentCart\App\Models\Product;
13 use FluentCart\App\Models\ProductVariation;
14 use FluentCart\App\Modules\Templating\AssetLoader;
15 use FluentCart\App\Services\Renderer\ModalCheckoutRenderer;
16 use FluentCart\App\Services\Renderer\ProductRenderer;
17 use FluentCart\App\Services\Translations\TransStrings;
18 use FluentCart\App\Vite;
19 use FluentCart\Framework\Support\Arr;
20
21 class BuyNowButtonBlockEditor extends BlockEditor
22 {
23 protected static string $editorName = 'buy-now-button';
24
25 public function getScripts(): array
26 {
27 return [
28 [
29 'source' => 'admin/BlockEditor/Buttons/BuyNowButtonBlockEditor.jsx',
30 'dependencies' => ['wp-blocks', 'wp-components']
31 ]
32 ];
33 }
34
35 public function supports(): array
36 {
37 return [
38 'html' => false,
39 'typography' => [
40 'fontSize' => true,
41 'lineHeight' => true
42 ],
43 'spacing' => [
44 'margin' => true,
45 'padding' => true
46 ],
47 'color' => [
48 'text' => true,
49 'background' => true,
50 ],
51 '__experimentalBorder' => [
52 'color' => true,
53 'radius' => true,
54 'style' => true,
55 'width' => true,
56 ],
57 'shadow' => true
58 ];
59 }
60
61 public function getStyles(): array
62 {
63 return [
64 'admin/BlockEditor/Buttons/style/button-block-editor.scss'
65 ];
66 }
67
68
69 public function localizeData(): array
70 {
71 return [
72 $this->getLocalizationKey() => [
73 'slug' => $this->slugPrefix,
74 'name' => static::getEditorName(),
75 'title' => __('Buy Now', 'fluent-cart'),
76 'description' => __('A custom button block with product selection and automatic link assignment.', 'fluent-cart'),
77 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg'),
78 ],
79 'fluent_cart_block_translation' => TransStrings::blockStrings(),
80 'fluent_cart_block_editor_asset' => [
81 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg'),
82 ],
83 ];
84 }
85
86 public function render(array $shortCodeAttribute, $block = null)
87 {
88 AssetLoader::loadSingleProductAssets();
89
90 $variantIds = Arr::get($shortCodeAttribute, 'variant_ids', []);
91 $variantId = Arr::get($variantIds, 0);
92
93 if (!$variantId) {
94 if(Helper::isAdminUser()){
95 return '<p class="fct-admin-notice">' . esc_html__('No variant selected', 'fluent-cart') . '</p>';
96 }
97 return '';
98 }
99
100 $variant = ProductVariation::query()->find($variantId);
101
102 if (!$variant) {
103 if(Helper::isAdminUser()){
104 return '<p class="fct-admin-notice">' . esc_html__('Invalid variant', 'fluent-cart') . '</p>';
105 }
106
107 return '';
108 }
109
110 $product = Product::query()->find($variant->post_id);
111
112 if (!$product) {
113 if(Helper::isAdminUser()){
114 return '<p class="fct-admin-notice">' . esc_html__('Product not found', 'fluent-cart') . '</p>';
115 }
116
117 return '';
118 }
119
120 ob_start();
121 (new ProductRenderer($product))->renderBuyNowButtonBlock($shortCodeAttribute);
122 return ob_get_clean();
123 }
124
125
126 }
127