PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.1
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 1.1.2 All 80 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.11.1, at includes/blocks/storeengine-product-summary/block.php

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