PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
ablocks / includes / blocks / storeengine-product-summary / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.14.0, at includes/blocks/storeengine-product-summary/block.php

319 lines 12.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ABlocks\Blocks\StoreengineProductSummary;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use ABlocks\Classes\BlockBaseAbstract;
10 use ABlocks\Classes\CssGenerator;
11 use ABlocks\Helper;
12 use ABlocks\Controls\Typography;
13 use ABlocks\Controls\Background;
14 use ABlocks\Controls\Border;
15 use ABlocks\Controls\Dimensions;
16 use ABlocks\Controls\Range;
17 use ABlocks\Controls\BoxShadow;
18 use ABlocks\Controls\Color;
19
20 class Block extends BlockBaseAbstract {
21 protected $block_name = 'storeengine-product-summary';
22
23 public function build_css( $attributes ) {
24 $css_generator = new CssGenerator( $attributes, $this->block_name );
25
26 $css_generator->add_class_styles(
27 '{{WRAPPER}} .storeengine-single__title',
28 $this->get_product_title_css( $attributes ),
29 $this->get_product_title_css( $attributes, 'Tablet' ),
30 $this->get_product_title_css( $attributes, 'Mobile' ),
31 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_product_title_css( $attributes, $device ); } )
32 );
33 $css_generator->add_class_styles(
34 '{{WRAPPER}} .storeengine-single__title:hover',
35 $this->get_product_title_hover_css( $attributes ),
36 $this->get_product_title_hover_css( $attributes, 'Tablet' ),
37 $this->get_product_title_hover_css( $attributes, 'Mobile' ),
38 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_product_title_hover_css( $attributes, $device ); } )
39 );
40 $css_generator->add_class_styles(
41 '{{WRAPPER}} .storeengine-single-product-simple-price .storeengine-price',
42 $this->get_product_price_css( $attributes ),
43 $this->get_product_price_css( $attributes, 'Tablet' ),
44 $this->get_product_price_css( $attributes, 'Mobile' ),
45 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_product_price_css( $attributes, $device ); } )
46 );
47 $css_generator->add_class_styles(
48 '{{WRAPPER}} .storeengine-single-product-simple-price .storeengine-price:hover',
49 $this->get_product_price_hover_css( $attributes ),
50 $this->get_product_price_hover_css( $attributes, 'Tablet' ),
51 $this->get_product_price_hover_css( $attributes, 'Mobile' ),
52 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_product_price_hover_css( $attributes, $device ); } )
53 );
54 $css_generator->add_class_styles(
55 '{{WRAPPER}} .storeengine-single-product-quantity input[type=number]',
56 $this->get_input_box_css( $attributes ),
57 $this->get_input_box_css( $attributes, 'Tablet' ),
58 $this->get_input_box_css( $attributes, 'Mobile' ),
59 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_input_box_css( $attributes, $device ); } )
60 );
61 $css_generator->add_class_styles(
62 '{{WRAPPER}} .storeengine-single-product-quantity input[type=number]:hover',
63 $this->get_input_box_hover_css( $attributes ),
64 $this->get_input_box_hover_css( $attributes, 'Tablet' ),
65 $this->get_input_box_hover_css( $attributes, 'Mobile' ),
66 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_input_box_hover_css( $attributes, $device ); } )
67 );
68 $css_generator->add_class_styles(
69 '{{WRAPPER}} .storeengine-btn--direct-checkout',
70 $this->get_button_css( $attributes ),
71 $this->get_button_css( $attributes, 'Tablet' ),
72 $this->get_button_css( $attributes, 'Mobile' ),
73 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_css( $attributes, $device ); } )
74 );
75 $css_generator->add_class_styles(
76 '{{WRAPPER}} .storeengine-btn--direct-checkout:hover',
77 $this->get_button_hover_css( $attributes ),
78 $this->get_button_hover_css( $attributes, 'Tablet' ),
79 $this->get_button_hover_css( $attributes, 'Mobile' ),
80 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_button_hover_css( $attributes, $device ); } )
81 );
82 $css_generator->add_class_styles(
83 '{{WRAPPER}} .storeengine-ajax-add-to-cart-form__entry-footer .storeengine-btn--add-to-cart',
84 $this->get_add_button_css( $attributes ),
85 $this->get_add_button_css( $attributes, 'Tablet' ),
86 $this->get_add_button_css( $attributes, 'Mobile' ),
87 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_add_button_css( $attributes, $device ); } )
88 );
89 $css_generator->add_class_styles(
90 '{{WRAPPER}} .storeengine-ajax-add-to-cart-form__entry-footer .storeengine-btn--add-to-cart:hover',
91 $this->get_add_hover_button_css( $attributes ),
92 $this->get_add_hover_button_css( $attributes, 'Tablet' ),
93 $this->get_add_hover_button_css( $attributes, 'Mobile' ),
94 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_add_hover_button_css( $attributes, $device ); } )
95 );
96
97 return $css_generator->generate_css();
98 }
99
100 public function get_button_css( $attributes, $device = '' ) {
101 $css = [];
102 $css['color'] = $attributes['buttonColor'] ?? '';
103 $css['background'] = $attributes['buttonBackground'] ?? '';
104 $alignment_css = [];
105 $typography_global = isset( $attributes['btnTypographyGlobal'] ) ? $attributes['btnTypographyGlobal'] : '';
106
107 $typography_value = isset( $attributes['btnTypography'] ) ? Typography::get_css( $attributes['btnTypography'], '', $device, $typography_global ) : array();
108
109 if ( ! empty( $attributes['buttonPadding'] ) ) {
110 $cssPadding = Dimensions::get_css( $attributes['buttonPadding'], 'padding', $device );
111 }
112
113 if ( ! empty( $attributes['buttonTextAlign'][ 'value' . $device ] ) ) {
114 $alignment_css['justify-content'] = $attributes['buttonTextAlign'][ 'value' . $device ];
115 }
116
117 return array_merge(
118 $css,
119 $typography_value,
120 $cssPadding,
121 $alignment_css,
122 Border::get_css( $attributes['buttonBorder'], '', $device ),
123 // BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
124 Range::get_css( [
125 'attributeValue' => $attributes['buttonWidth'],
126 'attribute_object_key' => 'value',
127 'isResponsive' => true,
128 'defaultValue' => 100,
129 'hasUnit' => true,
130 'unitDefaultValue' => '%',
131 'property' => 'width',
132 'device' => $device,
133 ] )
134 );
135 }
136
137 public function get_button_hover_css( $attributes, $device = '' ) {
138 $css = [];
139 $css['color'] = $attributes['buttonColorH'] ?? '';
140 $css['background'] = $attributes['buttonBackgroundH'] ?? '';
141
142 return array_merge(
143 $css,
144 Border::get_hover_css( $attributes['buttonBorder'] ?? [], '', $device ),
145 // BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ),
146 );
147 }
148
149 public function get_add_button_css( $attributes, $device = '' ) {
150 $css = [];
151 $css['color'] = $attributes['AddButtonColor'] ?? '';
152 $css['background'] = $attributes['AddButtonBackground'] ?? '';
153 $alignment_css = [];
154 $typography_global = isset( $attributes['AddBtnTypographyGlobal'] ) ? $attributes['AddBtnTypographyGlobal'] : '';
155
156 $typography_value = isset( $attributes['AddBtnTypography'] ) ? Typography::get_css( $attributes['btnTypography'], '', $device, $typography_global ) : array();
157
158 if ( ! empty( $attributes['buttonPadding'] ) ) {
159 $cssPadding = Dimensions::get_css( $attributes['AddButtonPadding'], 'padding', $device );
160 }
161
162 // if ( ! empty( $attributes['buttonTextAlign'][ 'value' . $device ] ) ) {
163 // $alignment_css['justify-content'] = $attributes['uttonTextAlign'][ 'value' . $device ];
164 // }
165
166 return array_merge(
167 $css,
168 $typography_value,
169 $cssPadding,
170 $alignment_css,
171 Border::get_css( $attributes['AddButtonBorder'], '', $device ),
172 // BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
173 Range::get_css( [
174 'attributeValue' => $attributes['AddButtonWidth'],
175 'attribute_object_key' => 'value',
176 'isResponsive' => true,
177 'defaultValue' => 100,
178 'hasUnit' => true,
179 'unitDefaultValue' => '%',
180 'property' => 'width',
181 'device' => $device,
182 ] )
183 );
184 }
185
186 public function get_add_hover_button_css( $attributes, $device = '' ) {
187 $css = [];
188 $css['color'] = $attributes['buttonColorH'] ?? '';
189 $css['background'] = $attributes['buttonBackgroundH'] ?? '';
190
191 return array_merge(
192 $css,
193 Border::get_hover_css( $attributes['buttonBorder'] ?? [], '', $device ),
194 // BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ),
195 );
196 }
197
198 public function get_product_title_css( $attributes, $device = '' ) {
199 $typography_global = isset( $attributes['titleTypographyGlobal'] ) ? $attributes['titleTypographyGlobal'] : '';
200
201 $typography_value = isset( $attributes['titleTypography'] ) ? Typography::get_css( $attributes['titleTypography'], '', $device, $typography_global ) : array();
202
203 return array_merge(
204 $typography_value,
205 [
206 'color' => Color::get_css(
207 isset( $attributes['titleColor'] ) ? $attributes['titleColor'] : ''
208 ),
209 ]
210 );
211 }
212
213 public function get_product_title_hover_css( $attributes, $device = '' ) {
214 return [
215 'color' => Color::get_css(
216 isset( $attributes['titleColorH'] ) ? $attributes['titleColorH'] : ''
217 ),
218 ];
219 }
220
221 public function get_product_price_css( $attributes, $device = '' ) {
222 $typography_global = isset( $attributes['ProductPriceTypographyGlobal'] ) ? $attributes['ProductPriceTypographyGlobal'] : '';
223
224 $typography_value = isset( $attributes['ProductPriceTypography'] ) ? Typography::get_css( $attributes['ProductPriceTypography'], '', $device, $typography_global ) : array();
225
226 return array_merge(
227 $typography_value,
228 [
229 'color' => Color::get_css(
230 isset( $attributes['productPriceColor'] ) ? $attributes['productPriceColor'] : ''
231 ),
232 ]
233 );
234 }
235
236 public function get_product_price_hover_css( $attributes, $device = '' ) {
237 return [
238 'color' => Color::get_css(
239 isset( $attributes['productPriceColorH'] ) ? $attributes['productPriceColorH'] : ''
240 ),
241 ];
242 }
243
244 public function get_input_box_css( $attributes, $device = '' ) {
245 $typography_value = isset( $attributes['inputTextTypography'] ) ? Typography::get_css( $attributes['inputTextTypography'], '', $device ) : array();
246 if ( ! empty( $attributes['inputPadding'] ) ) {
247 $css_padding = Dimensions::get_css( $attributes['inputPadding'], 'padding', $device );
248 }
249
250 return array_merge(
251 $typography_value,
252 $css_padding,
253 Border::get_css( $attributes['inputBorder'], '', $device ),
254 [
255 'color' => Color::get_css(
256 isset( $attributes['inputTextColor'] ) ? $attributes['inputTextColor'] : ''
257 ),
258 ],
259 Range::get_css( [
260 'attributeValue' => $attributes['inputWidth'],
261 'attribute_object_key' => 'value',
262 'isResponsive' => true,
263 'defaultValue' => 50,
264 'hasUnit' => true,
265 'unitDefaultValue' => 'px',
266 'property' => 'width',
267 'device' => $device,
268 ] ),
269 );
270 }
271
272 public function get_input_box_hover_css( $attributes, $device = '' ) {
273 return array_merge(
274 [
275 'color' => Color::get_css(
276 isset( $attributes['inputTextColorH'] ) ? $attributes['inputTextColorH'] : ''
277 ),
278 ],
279 Border::get_hover_css( $attributes['inputBorder'] ?? [], '', $device ),
280 );
281 }
282
283
284
285
286 public function render_block_content( $attributes, $content, $block_instance ) {
287 $attr_array = [
288 'product_id' => Helper::get_attribute_value( $attributes, 'product_id' ),
289 ];
290
291 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
292 $is_editor = ( isset( $_GET['context'] ) && 'edit' === sanitize_text_field( $_GET['context'] ) );
293
294 $is_custom = $attributes['isCustom'];
295
296 if ( $is_custom ) {
297 if ( empty( $attr_array['product_id'] ) && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) {
298 $attr_array['product_id'] = $block_instance->context['postId'];
299 }
300 } else {
301 if ( ! $is_editor && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) {
302 $attr_array['product_id'] = $block_instance->context['postId'];
303 }
304 }
305
306 if ( $is_editor && empty( $attr_array['product_id'] ) ) {
307 return '<p>Only in editor preview. Please Select a Product</p>';
308 }
309
310 if ( $is_editor ) {
311 $attr_array['dummy'] = true;
312 }
313
314 $shortcode = '[storeengine_single_product_summary ' . Helper::attr_shortcode( $attr_array ) . ']';
315 echo do_shortcode( $shortcode );
316 }
317
318 }
319