| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\Blocks\StoreengineCartList; |
| 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\Color; |
| 18 |
|
| 19 |
class Block extends BlockBaseAbstract { |
| 20 |
protected $block_name = 'storeengine-cart-list'; |
| 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-cart-table', |
| 27 |
$this->get_cart_list_table_css( $attributes ), |
| 28 |
$this->get_cart_list_table_css( $attributes, 'Tablet' ), |
| 29 |
$this->get_cart_list_table_css( $attributes, 'Mobile' ) |
| 30 |
); |
| 31 |
$css_generator->add_class_styles( |
| 32 |
'{{WRAPPER}} .storeengine-cart-table:hover', |
| 33 |
$this->get_cart_list_table_hover_css( $attributes ), |
| 34 |
$this->get_cart_list_table_hover_css( $attributes, 'Tablet' ), |
| 35 |
$this->get_cart_list_table_hover_css( $attributes, 'Mobile' ) |
| 36 |
); |
| 37 |
$css_generator->add_class_styles( |
| 38 |
'{{WRAPPER}} .storeengine-cart-table .storeengine-cart-table__head tr', |
| 39 |
$this->get_cart_list_table_header_css( $attributes ), |
| 40 |
$this->get_cart_list_table_header_css( $attributes, 'Tablet' ), |
| 41 |
$this->get_cart_list_table_header_css( $attributes, 'Mobile' ) |
| 42 |
); |
| 43 |
$css_generator->add_class_styles( |
| 44 |
'{{WRAPPER}} .storeengine-cart-table .storeengine-cart-table__head tr:hover', |
| 45 |
$this->get_cart_list_table_header_hover_css( $attributes ), |
| 46 |
$this->get_cart_list_table_header_hover_css( $attributes, 'Tablet' ), |
| 47 |
$this->get_cart_list_table_header_hover_css( $attributes, 'Mobile' ) |
| 48 |
); |
| 49 |
$css_generator->add_class_styles( |
| 50 |
'{{WRAPPER}} .storeengine-cart-list-table-shortcode .storeengine-cart-table__head tr th', |
| 51 |
$this->get_cart_list_table_header_text_css( $attributes ), |
| 52 |
$this->get_cart_list_table_header_text_css( $attributes, 'Tablet' ), |
| 53 |
$this->get_cart_list_table_header_text_css( $attributes, 'Mobile' ) |
| 54 |
); |
| 55 |
$css_generator->add_class_styles( |
| 56 |
'{{WRAPPER}} .storeengine-cart-product .storeengine-cart-product__content .storeengine-cart-product-title a', |
| 57 |
$this->get_cart_list_product_title( $attributes ), |
| 58 |
$this->get_cart_list_product_title( $attributes, 'Tablet' ), |
| 59 |
$this->get_cart_list_product_title( $attributes, 'Mobile' ) |
| 60 |
); |
| 61 |
$css_generator->add_class_styles( |
| 62 |
'{{WRAPPER}} .storeengine-cart-product .storeengine-cart-product__content .storeengine-cart-product-title a:hover', |
| 63 |
$this->get_cart_list_product_title_hover_css( $attributes ), |
| 64 |
$this->get_cart_list_product_title_hover_css( $attributes, 'Tablet' ), |
| 65 |
$this->get_cart_list_product_title_hover_css( $attributes, 'Mobile' ) |
| 66 |
); |
| 67 |
$css_generator->add_class_styles( |
| 68 |
'{{WRAPPER}} .storeengine-cart-product__content .storeengine-cart-product-price', |
| 69 |
$this->get_cart_list_subtitle_css( $attributes ), |
| 70 |
$this->get_cart_list_subtitle_css( $attributes, 'Tablet' ), |
| 71 |
$this->get_cart_list_subtitle_css( $attributes, 'Mobile' ) |
| 72 |
); |
| 73 |
$css_generator->add_class_styles( |
| 74 |
'{{WRAPPER}} .storeengine-cart-product__content .storeengine-cart-product-price:hover', |
| 75 |
$this->get_cart_list_subtitle_hover_css( $attributes ), |
| 76 |
$this->get_cart_list_subtitle_hover_css( $attributes, 'Tablet' ), |
| 77 |
$this->get_cart_list_subtitle_hover_css( $attributes, 'Mobile' ) |
| 78 |
); |
| 79 |
$css_generator->add_class_styles( |
| 80 |
'{{WRAPPER}} .storeengine-cart-list-table-shortcode .storeengine-cart-table__body-td .storeengine-price bdi', |
| 81 |
$this->get_cart_list_product_price_css( $attributes ), |
| 82 |
$this->get_cart_list_product_price_css( $attributes, 'Tablet' ), |
| 83 |
$this->get_cart_list_product_price_css( $attributes, 'Mobile' ) |
| 84 |
); |
| 85 |
$css_generator->add_class_styles( |
| 86 |
'{{WRAPPER}} .storeengine-cart-list-table-shortcode .storeengine-cart-table__body-td .storeengine-price bdi:hover', |
| 87 |
$this->get_cart_list_product_price_hover_css( $attributes ), |
| 88 |
$this->get_cart_list_product_price_hover_css( $attributes, 'Tablet' ), |
| 89 |
$this->get_cart_list_product_price_hover_css( $attributes, 'Mobile' ) |
| 90 |
); |
| 91 |
|
| 92 |
return $css_generator->generate_css(); |
| 93 |
} |
| 94 |
|
| 95 |
public function get_cart_list_table_css( $attributes, $device = '' ) { |
| 96 |
return [ 'background' => Color::get_css( isset( $attributes['tableBackground'] ) ? $attributes['tableBackground'] : '' ) ]; |
| 97 |
|
| 98 |
} |
| 99 |
public function get_cart_list_table_hover_css( $attributes, $device = '' ) { |
| 100 |
return array_merge( |
| 101 |
[ 'background' => Color::get_css( isset( $attributes['tableBackgroundH'] ) ? $attributes['tableBackgroundH'] : '' ) ], |
| 102 |
Range::get_css( [ |
| 103 |
'attributeValue' => isset( $attributes['tableTransition'] ) ? $attributes['tableTransition'] : '', |
| 104 |
'attribute_object_key' => 'value', |
| 105 |
'defaultValue' => 0, |
| 106 |
'unitDefaultValue' => 's', |
| 107 |
'property' => 'transition-duration', |
| 108 |
'device' => $device, |
| 109 |
] ), |
| 110 |
); |
| 111 |
} |
| 112 |
|
| 113 |
public function get_cart_list_table_header_css( $attributes, $device = '' ) { |
| 114 |
return [ 'background' => Color::get_css( isset( $attributes['tableHeaderBackground'] ) ? $attributes['tableHeaderBackground'] : '' ) ]; |
| 115 |
} |
| 116 |
|
| 117 |
public function get_cart_list_table_header_hover_css( $attributes, $device = '' ) { |
| 118 |
return array_merge( |
| 119 |
Range::get_css( [ |
| 120 |
'attributeValue' => isset( $attributes['tableTransition'] ) ? $attributes['tableTransition'] : '', |
| 121 |
'attribute_object_key' => 'value', |
| 122 |
'defaultValue' => 0, |
| 123 |
'unitDefaultValue' => 's', |
| 124 |
'property' => 'transition-duration', |
| 125 |
'device' => $device, |
| 126 |
] ), |
| 127 |
[ 'background' => Color::get_css( isset( $attributes['tableHeaderBackgroundH'] ) ? $attributes['tableHeaderBackgroundH'] : '' ) ] |
| 128 |
); |
| 129 |
} |
| 130 |
|
| 131 |
public function get_cart_list_table_header_text_css( $attributes, $device = '' ) { |
| 132 |
$typography = isset( $attributes['tableHeaderTypography'] ) && is_array( $attributes['tableHeaderTypography'] ) |
| 133 |
? $attributes['tableHeaderTypography'] |
| 134 |
: []; |
| 135 |
|
| 136 |
$typography_value = array_merge( $typography, [ 'font-weight' => '400' ] ); |
| 137 |
$typographyValueGlobal = ( isset( $attributes['tableHeaderTypographyGlobal'] ) ? $attributes['tableHeaderTypographyGlobal'] : '' ); |
| 138 |
|
| 139 |
return array_merge( |
| 140 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), |
| 141 |
); |
| 142 |
} |
| 143 |
|
| 144 |
public function get_cart_list_product_title( $attributes, $device = '' ) { |
| 145 |
$typography = isset( $attributes['productTilteTypography'] ) && is_array( $attributes['productTilteTypography'] ) |
| 146 |
? $attributes['productTilteTypography'] |
| 147 |
: array(); |
| 148 |
|
| 149 |
$typography_value = array_merge( $typography, [ 'font-weight' => '400' ] ); |
| 150 |
$typographyValueGlobal = ( isset( $attributes['productTitleTypographyGlobal'] ) ? $attributes['productTitleTypographyGlobal'] : '' ); |
| 151 |
|
| 152 |
return array_merge( |
| 153 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), |
| 154 |
[ 'color' => Color::get_css( isset( $attributes['productTitleColor'] ) ? $attributes['productTitleColor'] : '' ) ] |
| 155 |
); |
| 156 |
|
| 157 |
} |
| 158 |
public function get_cart_list_product_title_hover_css( $attributes, $device = '' ) { |
| 159 |
return [ 'color' => Color::get_css( isset( $attributes['productTitleColorH'] ) ? $attributes['productTitleColorH'] : '' ) ]; |
| 160 |
} |
| 161 |
|
| 162 |
public function get_cart_list_subtitle_css( $attributes, $device = '' ) { |
| 163 |
$typography = isset( $attributes['productsubTitleTypography'] ) && is_array( $attributes['productsubTitleTypography'] ) |
| 164 |
? $attributes['productsubTitleTypography'] |
| 165 |
: []; |
| 166 |
|
| 167 |
$typography_value = array_merge( $typography, [ 'font-weight' => '400' ] ); |
| 168 |
$typographyValueGlobal = ( isset( $attributes['productsubTitleTypographyGlobal'] ) ? $attributes['productsubTitleTypographyGlobal'] : '' ); |
| 169 |
return array_merge( |
| 170 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), |
| 171 |
[ 'color' => Color::get_css( isset( $attributes['productSubTiteColor'] ) ? $attributes['productSubTiteColor'] : '' ) ] |
| 172 |
); |
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
public function get_cart_list_subtitle_hover_css( $attributes, $device = '' ) { |
| 177 |
return [ 'color' => Color::get_css( isset( $attributes['productSubTiteColorH'] ) ? $attributes['productSubTiteColorH'] : '' ) ]; |
| 178 |
} |
| 179 |
public function get_cart_list_product_price_css( $attributes, $device = '' ) { |
| 180 |
$typography = isset( $attributes['productPriceTypography'] ) && is_array( $attributes['productPriceTypography'] ) |
| 181 |
? $attributes['productPriceTypography'] |
| 182 |
: []; |
| 183 |
|
| 184 |
$typography_value = array_merge( $typography, [ 'font-weight' => '400' ] ); |
| 185 |
$typographyValueGlobal = ( isset( $attributes['productPriceTypographyGlobal'] ) ? $attributes['productPriceTypographyGlobal'] : '' ); |
| 186 |
return array_merge( |
| 187 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), |
| 188 |
[ 'color' => Color::get_css( isset( $attributes['productPriceColor'] ) ? $attributes['productPriceColor'] : '' ) ] |
| 189 |
); |
| 190 |
|
| 191 |
} |
| 192 |
public function get_cart_list_product_price_hover_css( $attributes, $device = '' ) { |
| 193 |
return [ 'color' => Color::get_css( isset( $attributes['productPriceColorH'] ) ? $attributes['productPriceColorH'] : '' ) ]; |
| 194 |
} |
| 195 |
|
| 196 |
public function render_block_content( $attributes, $content, $block_instance ) { |
| 197 |
$attr_array = []; |
| 198 |
$shortcode = '[storeengine_cart_list_table ' . Helper::attr_shortcode( $attr_array ) . ']'; |
| 199 |
echo do_shortcode( $shortcode ); |
| 200 |
} |
| 201 |
|
| 202 |
} |
| 203 |
|