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 / Buttons / BuyNowButtonBlockEditor.php

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

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