| @@ -1,0 +1,137 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace ABlocks\Blocks\StoreengineOrderInfo; | |
| 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\Border; | |
| 14 | +use ABlocks\Controls\Dimensions; | |
| 15 | +use ABlocks\Controls\Range; | |
| 16 | +use ABlocks\Classes\CssGeneratorV2; | |
| 17 | +use ABlocks\Controls\Color; | |
| 18 | + | |
| 19 | +class Block extends BlockBaseAbstract { | |
| 20 | + protected $block_name = 'storeengine-order-info'; | |
| 21 | + | |
| 22 | + public function build_css_v1( $attributes ) { | |
| 23 | + $css_generator = new CssGenerator( $attributes ); | |
| 24 | + return $css_generator->generate_css(); | |
| 25 | + } | |
| 26 | + | |
| 27 | + public function build_css_v2( $attributes ) { | |
| 28 | + $css_generator = new CssGenerator( $attributes ); | |
| 29 | + | |
| 30 | + $css_generator->add_class_styles( | |
| 31 | + '{{WRAPPER}} .storeengine-thankyou-order-info-shortcode .storeengine-thankyou-order-info-success__content h4', | |
| 32 | + $this->get_status_title_css( $attributes ), | |
| 33 | + $this->get_status_title_css( $attributes, 'Tablet' ), | |
| 34 | + $this->get_status_title_css( $attributes, 'Mobile' ), | |
| 35 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_status_title_css( $attributes, $device ); } ) | |
| 36 | + ); | |
| 37 | + | |
| 38 | + $css_generator->add_class_styles( | |
| 39 | + '{{WRAPPER}} .storeengine-thankyou-order-info-shortcode .storeengine-thankyou-order-info-success__content h4:hover', | |
| 40 | + $this->get_status_title_hover_css( $attributes ), | |
| 41 | + $this->get_status_title_hover_css( $attributes, 'Tablet' ), | |
| 42 | + $this->get_status_title_hover_css( $attributes, 'Mobile' ), | |
| 43 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_status_title_hover_css( $attributes, $device ); } ) | |
| 44 | + ); | |
| 45 | + $css_generator->add_class_styles( | |
| 46 | + '{{WRAPPER}} .storeengine-thankyou-order-info-shortcode .storeengine-thankyou-order-info-success__content p span, | |
| 47 | + {{WRAPPER}} .storeengine-thankyou-order-info-shortcode .storeengine-thankyou-order-info-success__content p time', | |
| 48 | + $this->get_deatils_title_css( $attributes ), | |
| 49 | + $this->get_deatils_title_css( $attributes, 'Tablet' ), | |
| 50 | + $this->get_deatils_title_css( $attributes, 'Mobile' ), | |
| 51 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_deatils_title_css( $attributes, $device ); } ) | |
| 52 | + ); | |
| 53 | + | |
| 54 | + $css_generator->add_class_styles( | |
| 55 | + '{{WRAPPER}} .storeengine-thankyou-order-info-shortcode .storeengine-thankyou-order-info-success__content p span:hover, | |
| 56 | + {{WRAPPER}} .storeengine-thankyou-order-info-shortcode .storeengine-thankyou-order-info-success__content p time:hover', | |
| 57 | + $this->get_deatils_title_hover_css( $attributes ), | |
| 58 | + $this->get_deatils_title_hover_css( $attributes, 'Tablet' ), | |
| 59 | + $this->get_deatils_title_hover_css( $attributes, 'Mobile' ), | |
| 60 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_deatils_title_hover_css( $attributes, $device ); } ) | |
| 61 | + ); | |
| 62 | + $css_generator->add_class_styles( | |
| 63 | + '{{WRAPPER}} .storeengine-thankyou-order-info-shortcode .storeengine-thankyou-order-info-success .storeengine-thankyou-order-info-success__email p span, | |
| 64 | + {{WRAPPER}} .storeengine-thankyou-order-info-shortcode .storeengine-thankyou-order-info-success .storeengine-thankyou-order-info-success__email p a', | |
| 65 | + $this->get_email_css( $attributes ), | |
| 66 | + $this->get_email_css( $attributes, 'Tablet' ), | |
| 67 | + $this->get_email_css( $attributes, 'Mobile' ), | |
| 68 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_email_css( $attributes, $device ); } ) | |
| 69 | + ); | |
| 70 | + $css_generator->add_class_styles( | |
| 71 | + '{{WRAPPER}} .storeengine-thankyou-order-info-shortcode .storeengine-thankyou-order-info-success .storeengine-thankyou-order-info-success__email p span:hover, | |
| 72 | + {{WRAPPER}} .storeengine-thankyou-order-info-shortcode .storeengine-thankyou-order-info-success .storeengine-thankyou-order-info-success__email p a:hover', | |
| 73 | + $this->get_email_hover_css( $attributes ), | |
| 74 | + $this->get_email_hover_css( $attributes, 'Tablet' ), | |
| 75 | + $this->get_email_hover_css( $attributes, 'Mobile' ), | |
| 76 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_email_hover_css( $attributes, $device ); } ) | |
| 77 | + ); | |
| 78 | + | |
| 79 | + return $css_generator->generate_css(); | |
| 80 | + } | |
| 81 | + | |
| 82 | + public function build_css( $attributes ) { | |
| 83 | + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { | |
| 84 | + return $this->build_css_v2( $attributes ); | |
| 85 | + } | |
| 86 | + return $this->build_css_v1( $attributes ); | |
| 87 | + } | |
| 88 | + | |
| 89 | + public function get_status_title_css( $attributes, $device = '' ) { | |
| 90 | + $typographyGlobal = ( isset( $attributes['titleContentTypographyGlobal'] ) ? $attributes['titleContentTypographyGlobal'] : '' ); | |
| 91 | + $typography_value = ! empty( $attributes['titleContentTypography'] ) ? Typography::get_css( $attributes['titleContentTypography'], '', $device, $typographyGlobal ) : array(); | |
| 92 | + return array_merge( | |
| 93 | + [ 'color' => Color::get_css( isset( $attributes['titleContentColor'] ) ? $attributes['titleContentColor'] : '' ) ], | |
| 94 | + $typography_value | |
| 95 | + ); | |
| 96 | + } | |
| 97 | + public function get_status_title_hover_css( $attributes, $device = '' ) { | |
| 98 | + return [ 'color' => Color::get_css( isset( $attributes['titleContentColorH'] ) ? $attributes['titleContentColorH'] : '' ) ]; | |
| 99 | + } | |
| 100 | + public function get_deatils_title_css( $attributes, $device = '' ) { | |
| 101 | + $typographyGlobal = ( isset( $attributes['detailsTypographyGlobal'] ) ? $attributes['detailsTypographyGlobal'] : '' ); | |
| 102 | + $typography_value = ! empty( $attributes['detailsTypography'] ) ? Typography::get_css( $attributes['detailsTypography'], '', $device, $typographyGlobal ) : array(); | |
| 103 | + return array_merge( | |
| 104 | + [ 'color' => Color::get_css( isset( $attributes['detailsColor'] ) ? $attributes['detailsColor'] : '' ) ], | |
| 105 | + $typography_value | |
| 106 | + ); | |
| 107 | + } | |
| 108 | + | |
| 109 | + public function get_deatils_title_hover_css( $attributes, $device = '' ) { | |
| 110 | + return [ 'color' => Color::get_css( isset( $attributes['detailsColorH'] ) ? $attributes['detailsColorH'] : '' ) ]; | |
| 111 | + } | |
| 112 | + | |
| 113 | + public function get_email_css( $attributes, $device = '' ) { | |
| 114 | + $typographyGlobal = ( isset( $attributes['emailTypographyGlobal'] ) ? $attributes['emailTypographyGlobal'] : '' ); | |
| 115 | + $typography_value = ! empty( $attributes['emailTypography'] ) ? Typography::get_css( $attributes['emailTypography'], '', $device, $typographyGlobal ) : array(); | |
| 116 | + | |
| 117 | + return array_merge( | |
| 118 | + [ 'color' => Color::get_css( isset( $attributes['emailColor'] ) ? $attributes['emailColor'] : '' ) ], | |
| 119 | + $typography_value | |
| 120 | + ); | |
| 121 | + } | |
| 122 | + public function get_email_hover_css( $attributes, $device = '' ) { | |
| 123 | + return [ 'color' => Color::get_css( isset( $attributes['emailColorH'] ) ? $attributes['emailColorH'] : '' ) ]; | |
| 124 | + } | |
| 125 | + | |
| 126 | + public function render_block_content( $attributes, $content, $block_instance ) { | |
| 127 | + // StoreEngine core falls back to sample content when there's no real | |
| 128 | + // order (e.g. in the editor), so no dummy flag is needed here. | |
| 129 | + $attr_array = [ | |
| 130 | + 'ids' => Helper::get_attribute_value( $attributes, 'products_ids' ), | |
| 131 | + ]; | |
| 132 | + | |
| 133 | + $shortcode = '[storeengine_thankyou_order_info ' . Helper::attr_shortcode( $attr_array ) . ']'; | |
| 134 | + echo do_shortcode( $shortcode ); | |
| 135 | + } | |
| 136 | + | |
| 137 | +} | |