PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.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 1.1.2 All 80 releases
ablocks / includes / blocks / storeengine-products / block.php

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

188 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\StoreengineProducts;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Helper;
11 use ABlocks\Controls\Typography;
12 use ABlocks\Controls\Background;
13 use ABlocks\Controls\Border;
14 use ABlocks\Controls\Dimensions;
15 use ABlocks\Controls\Range;
16 use ABlocks\Controls\Alignment;
17 use ABlocks\Controls\Color;
18
19 class Block extends BlockBaseAbstract {
20 protected $block_name = 'storeengine-products';
21
22 public function build_css( $attributes ) {
23 $css_generator = new CssGenerator( $attributes, $this->block_name );
24
25 $css_generator->add_class_styles(
26 '{{WRAPPER}} .storeengine-products--grid .storeengine-products__body .storeengine-row .storeengine-product',
27 $this->get_products_card_css( $attributes ),
28 $this->get_products_card_css( $attributes, 'Tablet' ),
29 $this->get_products_card_css( $attributes, 'Mobile' )
30 );
31
32 $css_generator->add_class_styles(
33 '{{WRAPPER}} .storeengine-products--grid .storeengine-products__body .storeengine-row .storeengine-product:hover',
34 $this->get_products_card_hover_css( $attributes ),
35 $this->get_products_card_hover_css( $attributes, 'Tablet' ),
36 $this->get_products_card_hover_css( $attributes, 'Mobile' )
37 );
38 $css_generator->add_class_styles(
39 '{{WRAPPER}} .storeengine-products--grid .storeengine-row .storeengine-product .storeengine-product__body .storeengine-product__title,
40 {{WRAPPER}} .storeengine-products--grid .storeengine-row .storeengine-product .storeengine-product__body .storeengine-product__title a',
41 $this->get_products_card_title_css( $attributes ),
42 $this->get_products_card_title_css( $attributes, 'Tablet' ),
43 $this->get_products_card_title_css( $attributes, 'Mobile' )
44 );
45 $css_generator->add_class_styles(
46 '{{WRAPPER}} .storeengine-products--grid .storeengine-row .storeengine-product .storeengine-product__body .storeengine-product__title:hover,
47 {{WRAPPER}} .storeengine-products--grid .storeengine-row .storeengine-product .storeengine-product__body .storeengine-product__title:hover a',
48 $this->get_products_card_title_hover_css( $attributes ),
49 );
50 $css_generator->add_class_styles(
51 '{{WRAPPER}} .storeengine-ajax__amount .storeengine-product__simple-price',
52 $this->get_products_price_css( $attributes ),
53 $this->get_products_price_css( $attributes, 'Tablet' ),
54 $this->get_products_price_css( $attributes, 'Mobile' )
55 );
56 $css_generator->add_class_styles(
57 '{{WRAPPER}} .storeengine-add-to-cart-buttons .storeengine-btn',
58 $this->get_products_cart_button_css( $attributes ),
59 $this->get_products_cart_button_css( $attributes, 'Tablet' ),
60 $this->get_products_cart_button_css( $attributes, 'Mobile' )
61 );
62
63 $css_generator->add_class_styles(
64 '{{WRAPPER}} .storeengine-add-to-cart-buttons .storeengine-btn:hover',
65 $this->get_products_cart_button_hover_css( $attributes ),
66 $this->get_products_cart_button_hover_css( $attributes, 'Tablet' ),
67 $this->get_products_cart_button_hover_css( $attributes, 'Mobile' )
68 );
69 return $css_generator->generate_css();
70
71 }
72 public function get_products_card_title_hover_css( $attributes, $device = '' ) {
73
74 return [ 'color' => Color::get_css( isset( $attributes['title_hover_color'] ) ? $attributes['title_hover_color'] : '' ) ];
75 }
76 public function get_products_card_css( $attributes, $device = '' ) {
77 $products_background_css = ! empty( $attributes['card_background'] ) ? Background::get_css( $attributes['card_background'], 'background', $device ) : array();
78 $products_border_css = ! empty( $attributes['card_border'] ) ? Border::get_css( $attributes['card_border'], '', $device ) : array();
79 $products_margin_css = ! empty( $attributes['card_margin'] ) ? Dimensions::get_css( $attributes['card_margin'], 'margin', $device ) : array();
80 $products_padding_css = ! empty( $attributes['card_padding'] ) ? Dimensions::get_css( $attributes['card_padding'], 'padding', $device ) : array();
81
82 return array_merge(
83 $products_background_css,
84 $products_border_css,
85 $products_margin_css,
86 $products_padding_css
87 );
88 }
89
90 public function get_products_card_hover_css( $attributes, $device = '' ) {
91 $products_background_hover_css = ! empty( $attributes['card_background'] ) ? Background::get_hover_css( $attributes['card_background'], 'background', $device ) : array();
92 $products_border_hover_css = ! empty( $attributes['card_border'] ) ? Border::get_hover_css( $attributes['card_border'], '', $device ) : array();
93 $products_margin_hover_css = ! empty( $attributes['card_hover_margin'] ) ? Dimensions::get_css( $attributes['card_hover_margin'], 'margin', $device ) : array();
94 $products_padding_hover_css = ! empty( $attributes['card_hover_padding'] ) ? Dimensions::get_css( $attributes['card_hover_padding'], 'padding', $device ) : array();
95
96 return array_merge(
97 $products_background_hover_css,
98 $products_border_hover_css,
99 $products_margin_hover_css,
100 $products_padding_hover_css
101 );
102 }
103
104 public function get_products_price_css( $attributes, $device = '' ) {
105 $alignment_css = [];
106
107 if ( ! empty( $attributes['priceTextAlign'][ 'value' . $device ] ) ) {
108 $alignment_css['justify-content'] = $attributes['priceTextAlign'][ 'value' . $device ];
109 }
110
111 $typographyGlobal = ( isset( $attributes['price_typographyGlobal'] ) ? $attributes['price_typographyGlobal'] : '' );
112 $products_price_typography_css = ! empty( $attributes['price_typography'] ) ? Typography::get_css( $attributes['price_typography'], '', $device, $typographyGlobal ) : array();
113 return array_merge(
114 $alignment_css,
115 [ 'color' => Color::get_css( isset( $attributes['price_color'] ) ? $attributes['price_color'] : '' ) ],
116 $products_price_typography_css
117 );
118 }
119 public function get_products_card_title_css( $attributes, $device = '' ) {
120 $alignment_css = [];
121
122 if ( ! empty( $attributes['titleTextAlign'][ 'value' . $device ] ) ) {
123 $alignment_css['text-align'] = $attributes['titleTextAlign'][ 'value' . $device ];
124 }
125
126 $typographyGlobal = ( isset( $attributes['title_typographyGlobal'] ) ? $attributes['title_typographyGlobal'] : '' );
127 $course_title_typography_css = ! empty( $attributes['title_typography'] ) ? Typography::get_css( $attributes['title_typography'], '', $device, $typographyGlobal ) : array();
128 return array_merge(
129 $alignment_css,
130 [ 'color' => Color::get_css( isset( $attributes['title_color'] ) ? $attributes['title_color'] : '' ) ],
131 $course_title_typography_css
132 );
133 }
134
135 public function get_products_cart_button_css( $attributes, $device = '' ) {
136 $typographyGlobal = ( isset( $attributes['cart_button_typographyGlobal'] ) ? $attributes['cart_button_typographyGlobal'] : '' );
137 $typography_value = ! empty( $attributes['cart_button_typography'] ) ? Typography::get_css( $attributes['cart_button_typography'], '', $device, $typographyGlobal ) : array();
138 $products_border_css = ! empty( $attributes['cart_border'] ) ? Border::get_css( $attributes['cart_border'], '', $device ) : array();
139 return array_merge(
140 [ 'color' => Color::get_css( isset( $attributes['cart_button_text_color'] ) ? $attributes['cart_button_text_color'] : '' ) ],
141 [ 'background' => Color::get_css( isset( $attributes['cart_button_color'] ) ? $attributes['cart_button_color'] : '' ) ],
142 $typography_value,
143 $products_border_css,
144 Range::get_css([
145 'attributeValue' => $attributes['buttonWidth'],
146 'attribute_object_key' => 'value',
147 'isResponsive' => true,
148 'hasUnit' => true,
149 'defaultValue' => 100,
150 'unitDefaultValue' => '%',
151 'property' => 'width',
152 'device' => $device,
153 ])
154 );
155 }
156
157 public function get_products_cart_button_hover_css( $attributes, $device = '' ) {
158 $products_border_hover_css = ! empty( $attributes['cart_border'] ) ? Border::get_hover_css( $attributes['cart_border'], '', $device ) : array();
159
160 return array_merge(
161 $products_border_hover_css,
162 [ 'color' => Color::get_css( isset( $attributes['cart_button_text_hover_color'] ) ? $attributes['cart_button_text_hover_color'] : '' ) ],
163 [ 'background' => Color::get_css( isset( $attributes['cart_button_hover_color'] ) ? $attributes['cart_button_hover_color'] : '' ) ],
164 );
165 }
166
167 public function render_block_content( $attributes, $content, $block_instance ) {
168 $attr_array = [
169 'count' => Helper::get_attribute_value( $attributes, 'products_count' ),
170 'column_per_row' => Helper::get_attribute_value( $attributes, 'products_columns' ),
171 'has_pagination' => Helper::get_attribute_value( $attributes, 'show_pagination' ),
172 'products_level' => Helper::get_attribute_value( $attributes, 'difficulty_levels' ),
173 'price_type' => Helper::get_attribute_value( $attributes, 'price_types' ),
174 'orderby' => Helper::get_attribute_value( $attributes, 'order_by' ),
175 'order' => Helper::get_attribute_value( $attributes, 'products_order' ),
176 'ids' => Helper::get_attribute_value( $attributes, 'products_ids' ),
177 'exclude_ids' => Helper::get_attribute_value( $attributes, 'products_exclude_ids' ),
178 'category' => Helper::get_attribute_value( $attributes, 'products_categories' ),
179 'cat_not_in' => Helper::get_attribute_value( $attributes, 'products_exclude_categories' ),
180 'tag' => Helper::get_attribute_value( $attributes, 'products_tags' ),
181 'tag_not_in' => Helper::get_attribute_value( $attributes, 'products_exclude_tags' ),
182 ];
183 $shortcode = '[storeengine_products ' . Helper::attr_shortcode( $attr_array ) . ']';
184 echo do_shortcode( $shortcode );
185 }
186
187 }
188