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
← All changes | includes/blocks/storeengine-products/block.php +193 -0 2.7.5 → 2.14.0 View file →
@@ -1,0 +1,193 @@
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 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_products_card_css( $attributes, $device ); } )
31 + );
32 +
33 + $css_generator->add_class_styles(
34 + '{{WRAPPER}} .storeengine-products--grid .storeengine-products__body .storeengine-row .storeengine-product:hover',
35 + $this->get_products_card_hover_css( $attributes ),
36 + $this->get_products_card_hover_css( $attributes, 'Tablet' ),
37 + $this->get_products_card_hover_css( $attributes, 'Mobile' ),
38 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_products_card_hover_css( $attributes, $device ); } )
39 + );
40 + $css_generator->add_class_styles(
41 + '{{WRAPPER}} .storeengine-products--grid .storeengine-row .storeengine-product .storeengine-product__body .storeengine-product__title,
42 + {{WRAPPER}} .storeengine-products--grid .storeengine-row .storeengine-product .storeengine-product__body .storeengine-product__title a',
43 + $this->get_products_card_title_css( $attributes ),
44 + $this->get_products_card_title_css( $attributes, 'Tablet' ),
45 + $this->get_products_card_title_css( $attributes, 'Mobile' ),
46 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_products_card_title_css( $attributes, $device ); } )
47 + );
48 + $css_generator->add_class_styles(
49 + '{{WRAPPER}} .storeengine-products--grid .storeengine-row .storeengine-product .storeengine-product__body .storeengine-product__title:hover,
50 + {{WRAPPER}} .storeengine-products--grid .storeengine-row .storeengine-product .storeengine-product__body .storeengine-product__title:hover a',
51 + $this->get_products_card_title_hover_css( $attributes ),
52 + );
53 + $css_generator->add_class_styles(
54 + '{{WRAPPER}} .storeengine-ajax__amount .storeengine-product__simple-price',
55 + $this->get_products_price_css( $attributes ),
56 + $this->get_products_price_css( $attributes, 'Tablet' ),
57 + $this->get_products_price_css( $attributes, 'Mobile' ),
58 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_products_price_css( $attributes, $device ); } )
59 + );
60 + $css_generator->add_class_styles(
61 + '{{WRAPPER}} .storeengine-add-to-cart-buttons .storeengine-btn',
62 + $this->get_products_cart_button_css( $attributes ),
63 + $this->get_products_cart_button_css( $attributes, 'Tablet' ),
64 + $this->get_products_cart_button_css( $attributes, 'Mobile' ),
65 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_products_cart_button_css( $attributes, $device ); } )
66 + );
67 +
68 + $css_generator->add_class_styles(
69 + '{{WRAPPER}} .storeengine-add-to-cart-buttons .storeengine-btn:hover',
70 + $this->get_products_cart_button_hover_css( $attributes ),
71 + $this->get_products_cart_button_hover_css( $attributes, 'Tablet' ),
72 + $this->get_products_cart_button_hover_css( $attributes, 'Mobile' ),
73 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_products_cart_button_hover_css( $attributes, $device ); } )
74 + );
75 + return $css_generator->generate_css();
76 +
77 + }
78 + public function get_products_card_title_hover_css( $attributes, $device = '' ) {
79 +
80 + return [ 'color' => Color::get_css( isset( $attributes['title_hover_color'] ) ? $attributes['title_hover_color'] : '' ) ];
81 + }
82 + public function get_products_card_css( $attributes, $device = '' ) {
83 + $products_background_css = ! empty( $attributes['card_background'] ) ? Background::get_css( $attributes['card_background'], 'background', $device ) : array();
84 + $products_border_css = ! empty( $attributes['card_border'] ) ? Border::get_css( $attributes['card_border'], '', $device ) : array();
85 + $products_margin_css = ! empty( $attributes['card_margin'] ) ? Dimensions::get_css( $attributes['card_margin'], 'margin', $device ) : array();
86 + $products_padding_css = ! empty( $attributes['card_padding'] ) ? Dimensions::get_css( $attributes['card_padding'], 'padding', $device ) : array();
87 +
88 + return array_merge(
89 + $products_background_css,
90 + $products_border_css,
91 + $products_margin_css,
92 + $products_padding_css
93 + );
94 + }
95 +
96 + public function get_products_card_hover_css( $attributes, $device = '' ) {
97 + $products_background_hover_css = ! empty( $attributes['card_background'] ) ? Background::get_hover_css( $attributes['card_background'], 'background', $device ) : array();
98 + $products_border_hover_css = ! empty( $attributes['card_border'] ) ? Border::get_hover_css( $attributes['card_border'], '', $device ) : array();
99 + $products_margin_hover_css = ! empty( $attributes['card_hover_margin'] ) ? Dimensions::get_css( $attributes['card_hover_margin'], 'margin', $device ) : array();
100 + $products_padding_hover_css = ! empty( $attributes['card_hover_padding'] ) ? Dimensions::get_css( $attributes['card_hover_padding'], 'padding', $device ) : array();
101 +
102 + return array_merge(
103 + $products_background_hover_css,
104 + $products_border_hover_css,
105 + $products_margin_hover_css,
106 + $products_padding_hover_css
107 + );
108 + }
109 +
110 + public function get_products_price_css( $attributes, $device = '' ) {
111 + $alignment_css = [];
112 +
113 + if ( ! empty( $attributes['priceTextAlign'][ 'value' . $device ] ) ) {
114 + $alignment_css['justify-content'] = $attributes['priceTextAlign'][ 'value' . $device ];
115 + }
116 +
117 + $typographyGlobal = ( isset( $attributes['price_typographyGlobal'] ) ? $attributes['price_typographyGlobal'] : '' );
118 + $products_price_typography_css = ! empty( $attributes['price_typography'] ) ? Typography::get_css( $attributes['price_typography'], '', $device, $typographyGlobal ) : array();
119 + return array_merge(
120 + $alignment_css,
121 + [ 'color' => Color::get_css( isset( $attributes['price_color'] ) ? $attributes['price_color'] : '' ) ],
122 + $products_price_typography_css
123 + );
124 + }
125 + public function get_products_card_title_css( $attributes, $device = '' ) {
126 + $alignment_css = [];
127 +
128 + if ( ! empty( $attributes['titleTextAlign'][ 'value' . $device ] ) ) {
129 + $alignment_css['text-align'] = $attributes['titleTextAlign'][ 'value' . $device ];
130 + }
131 +
132 + $typographyGlobal = ( isset( $attributes['title_typographyGlobal'] ) ? $attributes['title_typographyGlobal'] : '' );
133 + $course_title_typography_css = ! empty( $attributes['title_typography'] ) ? Typography::get_css( $attributes['title_typography'], '', $device, $typographyGlobal ) : array();
134 + return array_merge(
135 + $alignment_css,
136 + [ 'color' => Color::get_css( isset( $attributes['title_color'] ) ? $attributes['title_color'] : '' ) ],
137 + $course_title_typography_css
138 + );
139 + }
140 +
141 + public function get_products_cart_button_css( $attributes, $device = '' ) {
142 + $typographyGlobal = ( isset( $attributes['cart_button_typographyGlobal'] ) ? $attributes['cart_button_typographyGlobal'] : '' );
143 + $typography_value = ! empty( $attributes['cart_button_typography'] ) ? Typography::get_css( $attributes['cart_button_typography'], '', $device, $typographyGlobal ) : array();
144 + $products_border_css = ! empty( $attributes['cart_border'] ) ? Border::get_css( $attributes['cart_border'], '', $device ) : array();
145 + return array_merge(
146 + [ 'color' => Color::get_css( isset( $attributes['cart_button_text_color'] ) ? $attributes['cart_button_text_color'] : '' ) ],
147 + [ 'background' => Color::get_css( isset( $attributes['cart_button_color'] ) ? $attributes['cart_button_color'] : '' ) ],
148 + $typography_value,
149 + $products_border_css,
150 + Range::get_css([
151 + 'attributeValue' => $attributes['buttonWidth'],
152 + 'attribute_object_key' => 'value',
153 + 'isResponsive' => true,
154 + 'hasUnit' => true,
155 + 'defaultValue' => 100,
156 + 'unitDefaultValue' => '%',
157 + 'property' => 'width',
158 + 'device' => $device,
159 + ])
160 + );
161 + }
162 +
163 + public function get_products_cart_button_hover_css( $attributes, $device = '' ) {
164 + $products_border_hover_css = ! empty( $attributes['cart_border'] ) ? Border::get_hover_css( $attributes['cart_border'], '', $device ) : array();
165 +
166 + return array_merge(
167 + $products_border_hover_css,
168 + [ 'color' => Color::get_css( isset( $attributes['cart_button_text_hover_color'] ) ? $attributes['cart_button_text_hover_color'] : '' ) ],
169 + [ 'background' => Color::get_css( isset( $attributes['cart_button_hover_color'] ) ? $attributes['cart_button_hover_color'] : '' ) ],
170 + );
171 + }
172 +
173 + public function render_block_content( $attributes, $content, $block_instance ) {
174 + $attr_array = [
175 + 'count' => Helper::get_attribute_value( $attributes, 'products_count' ),
176 + 'column_per_row' => Helper::get_attribute_value( $attributes, 'products_columns' ),
177 + 'has_pagination' => Helper::get_attribute_value( $attributes, 'show_pagination' ),
178 + 'products_level' => Helper::get_attribute_value( $attributes, 'difficulty_levels' ),
179 + 'price_type' => Helper::get_attribute_value( $attributes, 'price_types' ),
180 + 'orderby' => Helper::get_attribute_value( $attributes, 'order_by' ),
181 + 'order' => Helper::get_attribute_value( $attributes, 'products_order' ),
182 + 'ids' => Helper::get_attribute_value( $attributes, 'products_ids' ),
183 + 'exclude_ids' => Helper::get_attribute_value( $attributes, 'products_exclude_ids' ),
184 + 'category' => Helper::get_attribute_value( $attributes, 'products_categories' ),
185 + 'cat_not_in' => Helper::get_attribute_value( $attributes, 'products_exclude_categories' ),
186 + 'tag' => Helper::get_attribute_value( $attributes, 'products_tags' ),
187 + 'tag_not_in' => Helper::get_attribute_value( $attributes, 'products_exclude_tags' ),
188 + ];
189 + $shortcode = '[storeengine_products ' . Helper::attr_shortcode( $attr_array ) . ']';
190 + echo do_shortcode( $shortcode );
191 + }
192 +
193 +}