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