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