| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\StoreengineCheckoutForm; |
| 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\Border; |
| 13 |
use ABlocks\Controls\Dimensions; |
| 14 |
use ABlocks\Controls\Range; |
| 15 |
use ABlocks\Controls\Color; |
| 16 |
|
| 17 |
class Block extends BlockBaseAbstract { |
| 18 |
protected $block_name = 'storeengine-checkout-form'; |
| 19 |
|
| 20 |
public function build_css( $attributes ) { |
| 21 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 22 |
|
| 23 |
$css_generator->add_class_styles( |
| 24 |
'{{WRAPPER}} .storeengine-ajax-checkout-form__contact-information .storeengine-checkout-form-section-heading, |
| 25 |
{{WRAPPER}} .storeengine-ajax-checkout-form__billing-address .storeengine-checkout-form-section-heading', |
| 26 |
$this->get_Cheackout_form_css( $attributes ), |
| 27 |
$this->get_Cheackout_form_css( $attributes, 'Tablet' ), |
| 28 |
$this->get_Cheackout_form_css( $attributes, 'Mobile' ) |
| 29 |
); |
| 30 |
$css_generator->add_class_styles( |
| 31 |
'{{WRAPPER}} .storeengine-ajax-checkout-form__contact-information .storeengine-checkout-form-section-heading:hover, |
| 32 |
{{WRAPPER}} .storeengine-ajax-checkout-form__billing-address .storeengine-checkout-form-section-heading:hover', |
| 33 |
$this->get_Cheackout_form_hover_css( $attributes ), |
| 34 |
$this->get_Cheackout_form_hover_css( $attributes, 'Tablet' ), |
| 35 |
$this->get_Cheackout_form_hover_css( $attributes, 'Mobile' ) |
| 36 |
); |
| 37 |
$css_generator->add_class_styles( |
| 38 |
'{{WRAPPER}} .storeengine-form-group .storeengine-form__inner label, |
| 39 |
{{WRAPPER}} .storeengine-ajax-checkout-form__contact-information .storeengine-form-field .storeengine-form-field__inner label', |
| 40 |
$this->get_Cheackout_form_label_css( $attributes ), |
| 41 |
$this->get_Cheackout_form_label_css( $attributes, 'Tablet' ), |
| 42 |
$this->get_Cheackout_form_label_css( $attributes, 'Mobile' ) |
| 43 |
); |
| 44 |
$css_generator->add_class_styles( |
| 45 |
'{{WRAPPER}} .storeengine-form-group .storeengine-form__inner label:hover, |
| 46 |
{{WRAPPER}} .storeengine-ajax-checkout-form__contact-information .storeengine-form-field .storeengine-form-field__inner label:hover', |
| 47 |
$this->get_Cheackout_form_label_hover_css( $attributes ), |
| 48 |
$this->get_Cheackout_form_label_hover_css( $attributes, 'Tablet' ), |
| 49 |
$this->get_Cheackout_form_label_hover_css( $attributes, 'Mobile' ) |
| 50 |
); |
| 51 |
$css_generator->add_class_styles( |
| 52 |
'{{WRAPPER}} .storeengine-form-group .storeengine-form__inner input, |
| 53 |
{{WRAPPER}} .storeengine-ajax-checkout-form input', |
| 54 |
$this->get_Cheackout_form_input_css( $attributes ), |
| 55 |
$this->get_Cheackout_form_input_css( $attributes, 'Tablet' ), |
| 56 |
$this->get_Cheackout_form_input_css( $attributes, 'Mobile' ) |
| 57 |
); |
| 58 |
$css_generator->add_class_styles( |
| 59 |
'{{WRAPPER}} .storeengine-form-group .storeengine-form__inner input:hover, |
| 60 |
{{WRAPPER}} .storeengine-ajax-checkout-form input:hover', |
| 61 |
$this->get_Cheackout_form_input_hover_css( $attributes ), |
| 62 |
$this->get_Cheackout_form_input_hover_css( $attributes, 'Tablet' ), |
| 63 |
$this->get_Cheackout_form_input_hover_css( $attributes, 'Mobile' ) |
| 64 |
); |
| 65 |
$css_generator->add_class_styles( |
| 66 |
'{{WRAPPER}} .storeengine-form-group .storeengine-form__inner select', |
| 67 |
$this->get_cheackout_form_select_css( $attributes ), |
| 68 |
$this->get_cheackout_form_select_css( $attributes, 'Tablet' ), |
| 69 |
$this->get_cheackout_form_select_css( $attributes, 'Mobile' ) |
| 70 |
); |
| 71 |
$css_generator->add_class_styles( |
| 72 |
'{{WRAPPER}} .storeengine-form-group .storeengine-form__inner select:hover', |
| 73 |
$this->get_cheackout_form_select_hover_css( $attributes ), |
| 74 |
$this->get_cheackout_form_select_hover_css( $attributes, 'Tablet' ), |
| 75 |
$this->get_cheackout_form_select_hover_css( $attributes, 'Mobile' ) |
| 76 |
); |
| 77 |
$css_generator->add_class_styles( |
| 78 |
'{{WRAPPER}} .storeengine-ajax-checkout-form .storeengine-checkout__order-btn button', |
| 79 |
$this->get_cheackout_form_button_css( $attributes ), |
| 80 |
$this->get_cheackout_form_button_css( $attributes, 'Tablet' ), |
| 81 |
$this->get_cheackout_form_button_css( $attributes, 'Mobile' ) |
| 82 |
); |
| 83 |
$css_generator->add_class_styles( |
| 84 |
'{{WRAPPER}} .storeengine-ajax-checkout-form .storeengine-checkout__order-btn button:hover', |
| 85 |
$this->get_cheackout_form_button_hover_css( $attributes ), |
| 86 |
$this->get_cheackout_form_button_hover_css( $attributes, 'Tablet' ), |
| 87 |
$this->get_cheackout_form_button_hover_css( $attributes, 'Mobile' ) |
| 88 |
); |
| 89 |
|
| 90 |
return $css_generator->generate_css(); |
| 91 |
} |
| 92 |
public function get_Cheackout_form_css( $attributes, $device = '' ) { |
| 93 |
$typography = isset( $attributes['titleTypography'] ) && is_array( $attributes['titleTypography'] ) |
| 94 |
? $attributes['titleTypography'] |
| 95 |
: []; |
| 96 |
|
| 97 |
$typography_value = array_merge( $typography, [ 'font-weight' => '400' ] ); |
| 98 |
$typographyValueGlobal = ( isset( $attributes['titleTypographyGlobal'] ) ? $attributes['titleTypographyGlobal'] : '' ); |
| 99 |
|
| 100 |
return array_merge( |
| 101 |
[ 'color' => Color::get_css( isset( $attributes['titleColor'] ) ? $attributes['titleColor'] : '' ) ], |
| 102 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), |
| 103 |
); |
| 104 |
|
| 105 |
} |
| 106 |
|
| 107 |
public function get_Cheackout_form_hover_css( $attributes, $device = '' ) { |
| 108 |
return [ 'color' => Color::get_css( isset( $attributes['titleColorH'] ) ? $attributes['titleColorH'] : '' ) ]; |
| 109 |
} |
| 110 |
|
| 111 |
public function get_Cheackout_form_label_css( $attributes, $device = '' ) { |
| 112 |
$typography = isset( $attributes['labelTypography'] ) && is_array( $attributes['labelTypography'] ) |
| 113 |
? $attributes['labelTypography'] |
| 114 |
: []; |
| 115 |
|
| 116 |
$typography_value = array_merge( $typography, [ 'font-weight' => '400' ] ); |
| 117 |
$typographyValueGlobal = ( isset( $attributes['labelTypographyGlobal'] ) ? $attributes['labelTypographyGlobal'] : '' ); |
| 118 |
|
| 119 |
return array_merge( |
| 120 |
[ 'color' => Color::get_css( isset( $attributes['labelColor'] ) ? $attributes['labelColor'] : '' ) ], |
| 121 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), |
| 122 |
); |
| 123 |
} |
| 124 |
public function get_Cheackout_form_label_hover_css( $attributes, $device = '' ) { |
| 125 |
return [ 'color' => Color::get_css( isset( $attributes['labelColorH'] ) ? $attributes['labelColorH'] : '' ) ]; |
| 126 |
} |
| 127 |
public function get_Cheackout_form_input_css( $attributes, $device = '' ) { |
| 128 |
|
| 129 |
if ( ! empty( $attributes['padding'] ) ) { |
| 130 |
$cssPadding = Dimensions::get_css( $attributes['padding'], 'padding', $device ); |
| 131 |
} |
| 132 |
|
| 133 |
return array_merge( |
| 134 |
$cssPadding, |
| 135 |
Border::get_css( $attributes['inputBorder'], '', $device ), |
| 136 |
); |
| 137 |
|
| 138 |
} |
| 139 |
public function get_Cheackout_form_input_hover_css( $attributes, $device = '' ) { |
| 140 |
return array_merge( |
| 141 |
Border::get_hover_css( $attributes['buttonBorder'] ?? [], '', $device ), |
| 142 |
); |
| 143 |
} |
| 144 |
|
| 145 |
public function get_cheackout_form_select_css( $attributes, $device = '' ) { |
| 146 |
$typographyValue = ! empty( $attributes['selectTypography'] ) ? $attributes['selectTypography'] : []; |
| 147 |
$typographyValueGlobal = ( isset( $attributes['selectTypographyGlobal'] ) ? $attributes['selectTypographyGlobal'] : '' ); |
| 148 |
if ( ! empty( $attributes['selectPadding'] ) ) { |
| 149 |
$cssPadding = Dimensions::get_css( $attributes['selectPadding'], '', $device ); |
| 150 |
} |
| 151 |
|
| 152 |
if ( ! empty( $attributes['selectBorder'] ) ) { |
| 153 |
$cssBorder = Border::get_css( $attributes['selectBorder'], '', $device ); |
| 154 |
} |
| 155 |
|
| 156 |
return array_merge( |
| 157 |
[ 'color' => Color::get_css( isset( $attributes['selectTextcolor'] ) ? $attributes['selectTextcolor'] : '' ) ], |
| 158 |
[ 'background' => Color::get_css( isset( $attributes['selectBackground'] ) ? $attributes['selectBackground'] : '' ) ], |
| 159 |
Range::get_css([ |
| 160 |
'attributeValue' => $attributes['selectWidth'], |
| 161 |
'attribute_object_key' => 'value', |
| 162 |
'isResponsive' => true, |
| 163 |
'hasUnit' => true, |
| 164 |
'defaultValue' => 200, |
| 165 |
'property' => 'width', |
| 166 |
'unitDefaultValue' => 'px', |
| 167 |
'device' => $device, |
| 168 |
]), |
| 169 |
$cssBorder, |
| 170 |
$cssPadding, |
| 171 |
Typography::get_css( $typographyValue, '', $device, $typographyValueGlobal ) |
| 172 |
// $cssWidth, |
| 173 |
); |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
public function get_cheackout_form_button_css( $attributes, $device = '' ) { |
| 178 |
$typographyValue = ! empty( $attributes['buttonTypography'] ) ? $attributes['buttonTypography'] : []; |
| 179 |
$typographyValueGlobal = ( isset( $attributes['buttonTypographyGlobal'] ) ? $attributes['buttonTypographyGlobal'] : '' ); |
| 180 |
|
| 181 |
return array_merge( |
| 182 |
[ 'color' => Color::get_css( isset( $attributes['buttonColor'] ) ? $attributes['buttonColor'] : '' ) ], |
| 183 |
[ 'background' => Color::get_css( isset( $attributes['buttonBackground'] ) ? $attributes['buttonBackground'] : '' ) ], |
| 184 |
Typography::get_css( $typographyValue, '', $device, $typographyValueGlobal ) |
| 185 |
); |
| 186 |
} |
| 187 |
|
| 188 |
public function get_cheackout_form_button_hover_css( $attributes, $device = '' ) { |
| 189 |
return array_merge( |
| 190 |
[ 'color' => Color::get_css( isset( $attributes['buttonColorH'] ) ? $attributes['buttonColorH'] : '' ) ], |
| 191 |
[ 'background' => Color::get_css( isset( $attributes['buttonBackgroundH'] ) ? $attributes['buttonBackgroundH'] : '' ) ], |
| 192 |
); |
| 193 |
} |
| 194 |
|
| 195 |
public function get_cheackout_form_select_hover_css( $attributes, $device = '' ) { |
| 196 |
if ( ! empty( $attributes['selectBorder'] ) ) { |
| 197 |
$cssBorder = Border::get_hover_css( $attributes['selectBorder'] ?? [], '', $device ); |
| 198 |
|
| 199 |
} |
| 200 |
return array_merge( |
| 201 |
[ 'color' => Color::get_css( isset( $attributes['selectTextcolorH'] ) ? $attributes['selectTextcolorH'] : '' ) ], |
| 202 |
[ 'background' => Color::get_css( isset( $attributes['selectBackgroundH'] ) ? $attributes['selectBackgroundH'] : '' ) ], |
| 203 |
$cssBorder, |
| 204 |
); |
| 205 |
} |
| 206 |
|
| 207 |
public function render_block_content( $attributes, $content, $block_instance ) { |
| 208 |
$attr_array = [ |
| 209 |
'ids' => Helper::get_attribute_value( $attributes, 'products_ids' ), |
| 210 |
]; |
| 211 |
$shortcode = '[storeengine_checkout_form ' . Helper::attr_shortcode( $attr_array ) . ']'; |
| 212 |
echo do_shortcode( $shortcode ); |
| 213 |
} |
| 214 |
} |
| 215 |
|