block.json
11 months ago
button-cart.php
6 months ago
button-quick-view.php
6 months ago
controller.php
6 months ago
index-rtl.css
11 months ago
index.asset.php
1 month ago
index.css
11 months ago
index.js
1 month ago
controller.php
38 lines
| 1 | <?php |
| 2 | $icon = $attributes['icon'] ?? 'plus'; |
| 3 | $product_id = $block->context['postId'] ?? null; |
| 4 | $show_icon = in_array( $attributes['quick_view_button_type'], [ 'icon', 'both' ], true ); |
| 5 | $show_text = in_array( $attributes['quick_view_button_type'], [ 'text', 'both' ], true ); |
| 6 | $icon_position = $attributes['icon_position'] ?? 'before'; |
| 7 | $label = $attributes['label'] ?? __( 'Quick Add', 'surecart' ); |
| 8 | $direct_add_to_cart = $attributes['direct_add_to_cart'] ?? true; |
| 9 | $quick_view_link = add_query_arg( 'product-quick-view', $product_id ); |
| 10 | $gap = ! empty( $attributes['style']['spacing']['blockGap'] ) ? \SureCart::block()->styles()->getBlockGapPresetCssVar( $attributes['style']['spacing']['blockGap'] ) : ''; |
| 11 | $alignment = ! empty( $attributes['style']['typography']['textAlign'] ) ? $attributes['style']['typography']['textAlign'] : ''; |
| 12 | $width_class = ! empty( $attributes['width'] ) ? 'has-custom-width wp-block-button__width-' . $attributes['width'] : ''; |
| 13 | |
| 14 | $style = ! empty( $gap ) |
| 15 | ? esc_attr( safecss_filter_attr( 'gap:' . $gap ) ) . ';' |
| 16 | : ''; |
| 17 | |
| 18 | if ( ! empty( $alignment ) ) { |
| 19 | $style .= 'justify-content:' . esc_attr( $alignment ) . ';'; |
| 20 | } |
| 21 | |
| 22 | $styles = sc_get_block_styles(); |
| 23 | |
| 24 | $wrapper_style = ''; |
| 25 | |
| 26 | if ( ! empty( $styles['declarations'] ) ) { |
| 27 | $wrapper_style .= ! empty( $styles['declarations']['margin-top'] ) ? esc_attr( safecss_filter_attr( 'margin-top:' . $styles['declarations']['margin-top'] ) ) . ';' : ''; |
| 28 | $wrapper_style .= ! empty( $styles['declarations']['margin-bottom'] ) ? esc_attr( safecss_filter_attr( 'margin-bottom:' . $styles['declarations']['margin-bottom'] ) ) . ';' : ''; |
| 29 | $wrapper_style .= ! empty( $styles['declarations']['margin-left'] ) ? esc_attr( safecss_filter_attr( 'margin-left:' . $styles['declarations']['margin-left'] ) ) . ';' : ''; |
| 30 | $wrapper_style .= ! empty( $styles['declarations']['margin-right'] ) ? esc_attr( safecss_filter_attr( 'margin-right:' . $styles['declarations']['margin-right'] ) ) . ';' : ''; |
| 31 | } |
| 32 | |
| 33 | // Determine if we should add directly to cart. |
| 34 | $product = sc_get_product(); |
| 35 | $should_direct_add = $direct_add_to_cart && empty( $product->has_options ); |
| 36 | |
| 37 | return $should_direct_add ? 'file:./button-cart.php' : 'file:./button-quick-view.php'; |
| 38 |