| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\Blocks\StoreengineOrderDetails; |
| 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\Classes\CssGeneratorV2; |
| 18 |
use ABlocks\Controls\Color; |
| 19 |
|
| 20 |
class Block extends BlockBaseAbstract { |
| 21 |
protected $block_name = 'storeengine-order-details'; |
| 22 |
|
| 23 |
public function build_css_v1( $attributes ) { |
| 24 |
$css_generator = new CssGenerator( $attributes ); |
| 25 |
return $css_generator->generate_css(); |
| 26 |
} |
| 27 |
|
| 28 |
public function build_css_v2( $attributes ) { |
| 29 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 30 |
|
| 31 |
// error_log(print_r($attributes)); |
| 32 |
|
| 33 |
$css_generator->add_class_styles( |
| 34 |
'{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-order-item__content .storeengine-order-item__title p', |
| 35 |
$this->get_order_details_css( $attributes ), |
| 36 |
$this->get_order_details_css( $attributes, 'Tablet' ), |
| 37 |
$this->get_order_details_css( $attributes, 'Mobile' ), |
| 38 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_css( $attributes, $device ); } ) |
| 39 |
); |
| 40 |
|
| 41 |
$css_generator->add_class_styles( |
| 42 |
'{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-order-item__content .storeengine-order-item__title p:hover', |
| 43 |
$this->get_order_details_hover_css( $attributes ), |
| 44 |
$this->get_order_details_hover_css( $attributes, 'Tablet' ), |
| 45 |
$this->get_order_details_hover_css( $attributes, 'Mobile' ), |
| 46 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_hover_css( $attributes, $device ); } ) |
| 47 |
); |
| 48 |
$css_generator->add_class_styles( |
| 49 |
'{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-order-item__content img', |
| 50 |
$this->get_order_details_image_css( $attributes ), |
| 51 |
$this->get_order_details_image_css( $attributes, 'Tablet' ), |
| 52 |
$this->get_order_details_image_css( $attributes, 'Mobile' ), |
| 53 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_image_css( $attributes, $device ); } ) |
| 54 |
); |
| 55 |
$css_generator->add_class_styles( |
| 56 |
'{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-order-item__content .storeengine-order-item__title h6 a', |
| 57 |
$this->get_order_details_product_title_css( $attributes ), |
| 58 |
$this->get_order_details_product_title_css( $attributes, 'Tablet' ), |
| 59 |
$this->get_order_details_product_title_css( $attributes, 'Mobile' ), |
| 60 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_product_title_css( $attributes, $device ); } ) |
| 61 |
); |
| 62 |
$css_generator->add_class_styles( |
| 63 |
'{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-order-item__content .storeengine-order-item__title h6 a:hover', |
| 64 |
$this->get_order_details_product_title_hover_css( $attributes ), |
| 65 |
$this->get_order_details_product_title_hover_css( $attributes, 'Tablet' ), |
| 66 |
$this->get_order_details_product_title_hover_css( $attributes, 'Mobile' ), |
| 67 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_product_title_hover_css( $attributes, $device ); } ) |
| 68 |
); |
| 69 |
|
| 70 |
$css_generator->add_class_styles( |
| 71 |
'{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-order-item__price', |
| 72 |
$this->get_order_details_price_css( $attributes ), |
| 73 |
$this->get_order_details_price_css( $attributes, 'Tablet' ), |
| 74 |
$this->get_order_details_price_css( $attributes, 'Mobile' ), |
| 75 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_price_css( $attributes, $device ); } ) |
| 76 |
); |
| 77 |
$css_generator->add_class_styles( |
| 78 |
'{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-order-item__price:hover', |
| 79 |
$this->get_order_details_price_hover_css( $attributes ), |
| 80 |
$this->get_order_details_price_hover_css( $attributes, 'Tablet' ), |
| 81 |
$this->get_order_details_price_hover_css( $attributes, 'Mobile' ), |
| 82 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_price_hover_css( $attributes, $device ); } ) |
| 83 |
); |
| 84 |
$css_generator->add_class_styles( |
| 85 |
'{{WRAPPER}} .storeengine-order-summary-shortcode .storeengine-order-summary__item .storeengine-order-item-entry-right .storeengine-order-item__price .storeengine-order-item__price-regular', |
| 86 |
$this->get_order_details_regular_price_css( $attributes ), |
| 87 |
$this->get_order_details_regular_price_css( $attributes, 'Tablet' ), |
| 88 |
$this->get_order_details_regular_price_css( $attributes, 'Mobile' ), |
| 89 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_regular_price_css( $attributes, $device ); } ) |
| 90 |
); |
| 91 |
$css_generator->add_class_styles( |
| 92 |
'{{WRAPPER}} .storeengine-order-summary-shortcode .storeengine-order-summary__item .storeengine-order-item-entry-right .storeengine-order-item__price .storeengine-order-item__price-regular:hover', |
| 93 |
$this->get_order_details_price_regular_hover_css( $attributes ), |
| 94 |
$this->get_order_details_price_regular_hover_css( $attributes, 'Tablet' ), |
| 95 |
$this->get_order_details_price_regular_hover_css( $attributes, 'Mobile' ), |
| 96 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_price_regular_hover_css( $attributes, $device ); } ) |
| 97 |
); |
| 98 |
$css_generator->add_class_styles( |
| 99 |
'{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-order-item__content .storeengine-order-item__title p, |
| 100 |
{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-order-item__content .storeengine-order-item__title p span', |
| 101 |
$this->get_order_details_quality_css( $attributes ), |
| 102 |
$this->get_order_details_quality_css( $attributes, 'Tablet' ), |
| 103 |
$this->get_order_details_quality_css( $attributes, 'Mobile' ), |
| 104 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_quality_css( $attributes, $device ); } ) |
| 105 |
); |
| 106 |
$css_generator->add_class_styles( |
| 107 |
'{{WRAPPER}} .storeengine-order-summary-shortcode .storeengine-order-summary__item .storeengine-order-item-entry-right .storeengine-order-item__qty:hover, |
| 108 |
{{WRAPPER}} .storeengine-order-summary-shortcode .storeengine-order-summary__item .storeengine-order-item-entry-right .storeengine-order-item__qty span:hover', |
| 109 |
$this->get_order_details_quality_hover_css( $attributes ), |
| 110 |
$this->get_order_details_quality_hover_css( $attributes, 'Tablet' ), |
| 111 |
$this->get_order_details_quality_hover_css( $attributes, 'Mobile' ), |
| 112 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_order_details_quality_hover_css( $attributes, $device ); } ) |
| 113 |
); |
| 114 |
$css_generator->add_class_styles( |
| 115 |
'{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-thankyou-summery--item p, |
| 116 |
{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-thankyou-summery--item p span', |
| 117 |
$this->get_table_text_css( $attributes ), |
| 118 |
$this->get_table_text_css( $attributes, 'Tablet' ), |
| 119 |
$this->get_table_text_css( $attributes, 'Mobile' ), |
| 120 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_table_text_css( $attributes, $device ); } ) |
| 121 |
); |
| 122 |
$css_generator->add_class_styles( |
| 123 |
'{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-thankyou-summery--item p:hover, |
| 124 |
{{WRAPPER}} .storeengine-order-details-shortcode .storeengine-thankyou-summery--item p span:hover', |
| 125 |
$this->get_table_text_hover_css( $attributes ), |
| 126 |
$this->get_table_text_hover_css( $attributes, 'Tablet' ), |
| 127 |
$this->get_table_text_hover_css( $attributes, 'Mobile' ), |
| 128 |
$css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_table_text_hover_css( $attributes, $device ); } ) |
| 129 |
); |
| 130 |
|
| 131 |
return $css_generator->generate_css(); |
| 132 |
} |
| 133 |
|
| 134 |
public function build_css( $attributes ) { |
| 135 |
if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { |
| 136 |
return $this->build_css_v2( $attributes ); |
| 137 |
} |
| 138 |
return $this->build_css_v1( $attributes ); |
| 139 |
} |
| 140 |
|
| 141 |
public function get_order_details_css( $attributes, $device = '' ) { |
| 142 |
$title_typography_css = ! empty( $attributes['titleTypography'] ) ? $attributes['titleTypography'] : []; |
| 143 |
$typographyGlobal = ( isset( $attributes['titleTypographyGlobal'] ) ? $attributes['titleTypographyGlobal'] : '' ); |
| 144 |
|
| 145 |
return array_merge( |
| 146 |
[ 'color' => Color::get_css( isset( $attributes['titleColor'] ) ? $attributes['titleColor'] : '' ) ], |
| 147 |
Typography::get_css( $title_typography_css, '', $device, $typographyGlobal ) |
| 148 |
); |
| 149 |
} |
| 150 |
|
| 151 |
public function get_order_details_hover_css( $attributes, $device = '' ) { |
| 152 |
return array_merge( |
| 153 |
[ 'color' => Color::get_css( isset( $attributes['titleColorH'] ) ? $attributes['titleColorH'] : '' ) ], |
| 154 |
); |
| 155 |
} |
| 156 |
|
| 157 |
public function get_order_details_image_css( $attributes, $device = '' ) { |
| 158 |
return array_merge( |
| 159 |
Range::get_css([ |
| 160 |
'attributeValue' => $attributes['imageWidth'], |
| 161 |
'attribute_object_key' => 'value', |
| 162 |
'isResponsive' => true, |
| 163 |
'defaultValue' => 100, |
| 164 |
'hasUnit' => true, |
| 165 |
'unitDefaultValue' => 'px', |
| 166 |
'property' => 'width', |
| 167 |
'device' => $device, |
| 168 |
]), |
| 169 |
Range::get_css([ |
| 170 |
'attributeValue' => $attributes['imageHeight'], |
| 171 |
'attribute_object_key' => 'value', |
| 172 |
'isResponsive' => true, |
| 173 |
'defaultValue' => 100, |
| 174 |
'hasUnit' => true, |
| 175 |
'unitDefaultValue' => 'px', |
| 176 |
'property' => 'Height', |
| 177 |
'device' => $device, |
| 178 |
]), |
| 179 |
); |
| 180 |
|
| 181 |
} |
| 182 |
|
| 183 |
public function get_order_details_product_title_css( $attributes, $device = '' ) { |
| 184 |
$title_typography_css = ! empty( $attributes['ProductTitleTypography'] ) ? $attributes['ProductTitleTypography'] : []; |
| 185 |
$typographyGlobal = ( isset( $attributes['ProductTitleTypographyGlobal'] ) ? $attributes['ProductTitleTypographyGlobal'] : '' ); |
| 186 |
|
| 187 |
return array_merge( |
| 188 |
[ 'color' => Color::get_css( isset( $attributes['productTitleColor'] ) ? $attributes['productTitleColor'] : '' ) ], |
| 189 |
Typography::get_css( $title_typography_css, '', $device, $typographyGlobal ) |
| 190 |
); |
| 191 |
} |
| 192 |
|
| 193 |
public function get_order_details_product_title_hover_css( $attributes, $device = '' ) { |
| 194 |
return [ 'color' => Color::get_css( isset( $attributes['productTitleColorH'] ) ? $attributes['productTitleColorH'] : '' ) ]; |
| 195 |
} |
| 196 |
|
| 197 |
public function get_order_details_price_css( $attributes, $device = '' ) { |
| 198 |
$typography_value = isset( $attributes['discountPriceTypography'] ) ? $attributes['discountPriceTypography'] : []; |
| 199 |
$typographyGlobal = ( isset( $attributes['discountPriceTypographyGlobal'] ) ? $attributes['discountPriceTypographyGlobal'] : '' ); |
| 200 |
return array_merge( |
| 201 |
[ 'color' => Color::get_css( isset( $attributes['discountPriceColor'] ) ? $attributes['discountPriceColor'] : '' ) ], |
| 202 |
Typography::get_css( $typography_value, '', $device, $typographyGlobal ) |
| 203 |
); |
| 204 |
} |
| 205 |
|
| 206 |
public function get_order_details_price_hover_css( $attributes, $device = '' ) { |
| 207 |
return [ 'color' => Color::get_css( isset( $attributes['discountPriceColorH'] ) ? $attributes['discountPriceColorH'] : '' ) ]; |
| 208 |
|
| 209 |
} |
| 210 |
|
| 211 |
public function get_order_details_regular_price_css( $attributes, $device = '' ) { |
| 212 |
$typography_value = isset( $attributes['regularPriceTypography'] ) ? $attributes['regularPriceTypography'] : []; |
| 213 |
$typographyGlobal = ( isset( $attributes['regularPriceTypographyGlobal'] ) ? $attributes['regularPriceTypographyGlobal'] : '' ); |
| 214 |
|
| 215 |
return array_merge( |
| 216 |
[ 'color' => Color::get_css( isset( $attributes['regularPriceColor'] ) ? $attributes['regularPriceColor'] : '' ) ], |
| 217 |
Typography::get_css( $typography_value, '', $device, $typographyGlobal ) |
| 218 |
); |
| 219 |
} |
| 220 |
|
| 221 |
public function get_order_details_price_regular_hover_css( $attributes, $device = '' ) { |
| 222 |
return [ 'color' => Color::get_css( isset( $attributes['regularPriceColorH'] ) ? $attributes['regularPriceColorH'] : '' ) ]; |
| 223 |
|
| 224 |
} |
| 225 |
|
| 226 |
public function get_order_details_quality_css( $attributes, $device = '' ) { |
| 227 |
$typography_value = isset( $attributes['qualityTypography'] ) ? $attributes['qualityTypography'] : []; |
| 228 |
$typographyGlobal = ( isset( $attributes['qualityTypographyGlobal'] ) ? $attributes['qualityTypographyGlobal'] : '' ); |
| 229 |
|
| 230 |
return array_merge( |
| 231 |
[ 'color' => Color::get_css( isset( $attributes['qualityColor'] ) ? $attributes['qualityColor'] : '' ) ], |
| 232 |
Typography::get_css( $typography_value, '', $device, $typographyGlobal ) |
| 233 |
); |
| 234 |
} |
| 235 |
|
| 236 |
public function get_order_details_quality_hover_css( $attributes, $device = '' ) { |
| 237 |
return [ 'color' => Color::get_css( isset( $attributes['qualityColorH'] ) ? $attributes['qualityColorH'] : '' ) ]; |
| 238 |
|
| 239 |
} |
| 240 |
|
| 241 |
public function get_table_text_css( $attributes, $device = '' ) { |
| 242 |
$typography_value = isset( $attributes['tableTextTypography'] ) ? $attributes['tableTextTypography'] : []; |
| 243 |
$typographyGlobal = ( isset( $attributes['tableTextTypographyGlobal'] ) ? $attributes['tableTextTypographyGlobal'] : '' ); |
| 244 |
|
| 245 |
return array_merge( |
| 246 |
[ 'color' => Color::get_css( isset( $attributes['tableTextColor'] ) ? $attributes['tableTextColor'] : '' ) ], |
| 247 |
Typography::get_css( $typography_value, '', $device, $typographyGlobal ) |
| 248 |
); |
| 249 |
} |
| 250 |
public function get_table_text_hover_css( $attributes, $device = '' ) { |
| 251 |
|
| 252 |
return [ 'color' => Color::get_css( isset( $attributes['tableTextColorH'] ) ? $attributes['tableTextColorH'] : '#000' ) ]; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
public function render_block_content( $attributes, $content, $block_instance ) { |
| 257 |
// StoreEngine core falls back to sample content when there's no real |
| 258 |
// order (e.g. in the editor), so no dummy flag is needed here. |
| 259 |
echo do_shortcode( '[storeengine_order_details]' ); |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
|