Accordion
1 year ago
AddToCartWithOptions
1 week ago
OrderConfirmation
2 months ago
ProductCollection
3 weeks ago
Reviews
2 months ago
AbstractBlock.php
4 weeks ago
AbstractDynamicBlock.php
2 years ago
AbstractInnerBlock.php
1 year ago
AbstractProductGrid.php
3 months ago
ActiveFilters.php
2 years ago
AddToCartForm.php
4 weeks ago
AddToWishlistButton.php
4 weeks ago
AllProducts.php
2 years ago
AllReviews.php
2 years ago
AtomicBlock.php
2 years ago
AttributeFilter.php
1 year ago
Breadcrumbs.php
1 year ago
Cart.php
2 months ago
CartAcceptedPaymentMethodsBlock.php
2 years ago
CartCrossSellsBlock.php
2 years ago
CartCrossSellsProductsBlock.php
2 years ago
CartExpressPaymentBlock.php
1 year ago
CartItemsBlock.php
2 years ago
CartLineItemsBlock.php
2 years ago
CartLink.php
2 months ago
CartOrderSummaryBlock.php
2 years ago
CartOrderSummaryCouponFormBlock.php
2 years ago
CartOrderSummaryDiscountBlock.php
2 years ago
CartOrderSummaryFeeBlock.php
2 years ago
CartOrderSummaryHeadingBlock.php
2 years ago
CartOrderSummaryShippingBlock.php
2 years ago
CartOrderSummarySubtotalBlock.php
2 years ago
CartOrderSummaryTaxesBlock.php
2 years ago
CartOrderSummaryTotalsBlock.php
2 years ago
CartTotalsBlock.php
2 years ago
CatalogSorting.php
4 weeks ago
CategoryDescription.php
2 months ago
CategoryTitle.php
2 months ago
Checkout.php
2 months ago
CheckoutActionsBlock.php
1 year ago
CheckoutAdditionalInformationBlock.php
2 years ago
CheckoutBillingAddressBlock.php
2 years ago
CheckoutContactInformationBlock.php
2 years ago
CheckoutExpressPaymentBlock.php
9 months ago
CheckoutFieldsBlock.php
2 years ago
CheckoutOrderNoteBlock.php
2 years ago
CheckoutOrderSummaryBlock.php
2 years ago
CheckoutOrderSummaryCartItemsBlock.php
2 years ago
CheckoutOrderSummaryCouponFormBlock.php
2 years ago
CheckoutOrderSummaryDiscountBlock.php
2 years ago
CheckoutOrderSummaryFeeBlock.php
2 years ago
CheckoutOrderSummaryShippingBlock.php
2 years ago
CheckoutOrderSummarySubtotalBlock.php
2 years ago
CheckoutOrderSummaryTaxesBlock.php
2 years ago
CheckoutOrderSummaryTotalsBlock.php
2 years ago
CheckoutPaymentBlock.php
2 years ago
CheckoutPickupOptionsBlock.php
2 years ago
CheckoutShippingAddressBlock.php
2 years ago
CheckoutShippingMethodBlock.php
2 years ago
CheckoutShippingMethodsBlock.php
2 years ago
CheckoutTermsBlock.php
2 years ago
CheckoutTotalsBlock.php
2 years ago
ClassicShortcode.php
1 year ago
ClassicTemplate.php
4 months ago
ComingSoon.php
1 year ago
CouponCode.php
2 months ago
CustomerAccount.php
3 months ago
Dropdown.php
4 weeks ago
EmailContent.php
5 months ago
EmptyCartBlock.php
2 years ago
EmptyMiniCartContentsBlock.php
11 months ago
EnableBlockJsonAssetsTrait.php
1 year ago
FeaturedCategory.php
7 months ago
FeaturedItem.php
7 months ago
FeaturedProduct.php
7 months ago
FilledCartBlock.php
2 years ago
FilledMiniCartContentsBlock.php
4 months ago
FilterWrapper.php
2 years ago
HandpickedProducts.php
1 year ago
MiniCart.php
4 weeks ago
MiniCartCartButtonBlock.php
11 months ago
MiniCartCheckoutButtonBlock.php
11 months ago
MiniCartContents.php
3 months ago
MiniCartFooterBlock.php
4 weeks ago
MiniCartItemsBlock.php
11 months ago
MiniCartProductsTableBlock.php
4 weeks ago
MiniCartShoppingButtonBlock.php
9 months ago
MiniCartTitleBlock.php
11 months ago
MiniCartTitleItemsCounterBlock.php
11 months ago
MiniCartTitleLabelBlock.php
11 months ago
NextPreviousButtons.php
5 months ago
PageContentWrapper.php
2 years ago
PaymentMethodIcons.php
11 months ago
PriceFilter.php
1 year ago
ProceedToCheckoutBlock.php
2 years ago
ProductAverageRating.php
1 year ago
ProductBestSellers.php
2 years ago
ProductButton.php
2 months ago
ProductCategories.php
4 weeks ago
ProductCategory.php
2 years ago
ProductDescription.php
9 months ago
ProductDetails.php
5 months ago
ProductFilterActive.php
4 weeks ago
ProductFilterAttribute.php
4 weeks ago
ProductFilterCheckboxList.php
4 weeks ago
ProductFilterChips.php
4 weeks ago
ProductFilterClearButton.php
4 weeks ago
ProductFilterPrice.php
4 weeks ago
ProductFilterPriceSlider.php
4 weeks ago
ProductFilterRating.php
4 weeks ago
ProductFilterRemovableChips.php
4 weeks ago
ProductFilterStatus.php
4 weeks ago
ProductFilterTaxonomy.php
4 weeks ago
ProductFilters.php
3 weeks ago
ProductGallery.php
4 weeks ago
ProductGalleryLargeImage.php
4 weeks ago
ProductGalleryThumbnails.php
4 weeks ago
ProductImage.php
4 weeks ago
ProductImageGallery.php
7 months ago
ProductMeta.php
1 year ago
ProductNew.php
2 years ago
ProductOnSale.php
2 years ago
ProductPrice.php
2 months ago
ProductQuery.php
4 weeks ago
ProductRating.php
1 year ago
ProductRatingCounter.php
1 year ago
ProductRatingStars.php
1 year ago
ProductResultsCount.php
2 months ago
ProductSKU.php
2 months ago
ProductSaleBadge.php
1 year ago
ProductSearch.php
10 months ago
ProductSpecifications.php
2 months ago
ProductStockIndicator.php
2 months ago
ProductSummary.php
7 months ago
ProductTag.php
2 years ago
ProductTemplate.php
2 months ago
ProductTitle.php
1 year ago
ProductTopRated.php
2 years ago
ProductsByAttribute.php
2 years ago
RatingFilter.php
2 years ago
RelatedProducts.php
3 months ago
ReviewsByCategory.php
2 years ago
ReviewsByProduct.php
2 years ago
SavedForLater.php
4 weeks ago
SingleProduct.php
2 months ago
StockFilter.php
2 years ago
StoreNotices.php
1 year ago
Wishlist.php
4 weeks ago
MiniCartContents.php
209 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\Blocks\BlockTypes; |
| 3 | |
| 4 | use Automattic\WooCommerce\Admin\Features\Features; |
| 5 | use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils; |
| 6 | |
| 7 | /** |
| 8 | * Mini-Cart Contents class. |
| 9 | * |
| 10 | * @internal |
| 11 | */ |
| 12 | class MiniCartContents extends AbstractBlock { |
| 13 | /** |
| 14 | * Block name. |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | protected $block_name = 'mini-cart-contents'; |
| 19 | |
| 20 | /** |
| 21 | * Get the editor script handle for this block type. |
| 22 | * |
| 23 | * @param string $key Data to get, or default to everything. |
| 24 | * |
| 25 | * @return array|string; |
| 26 | */ |
| 27 | protected function get_block_type_editor_script( $key = null ) { |
| 28 | $script = [ |
| 29 | 'handle' => 'wc-' . $this->block_name . '-block', |
| 30 | 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ), |
| 31 | 'dependencies' => [ 'wc-blocks' ], |
| 32 | ]; |
| 33 | return $key ? $script[ $key ] : $script; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Get the frontend script handle for this block type. |
| 38 | * |
| 39 | * @param string $key Data to get, or default to everything. |
| 40 | * |
| 41 | * @return null |
| 42 | */ |
| 43 | protected function get_block_type_script( $key = null ) { |
| 44 | // The frontend script is a dependency of the Mini-Cart block so it's |
| 45 | // already lazy-loaded. |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Get the frontend style handle for this block type. |
| 51 | * |
| 52 | * @return string[] |
| 53 | */ |
| 54 | protected function get_block_type_style() { |
| 55 | return array_merge( parent::get_block_type_style(), [ 'wc-blocks-packages-style' ] ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Render experimental iAPI powered Mini-Cart Contents block. |
| 60 | * |
| 61 | * @param array $attributes Block attributes. |
| 62 | * @param string $content Block content. |
| 63 | * @param WP_Block $block Block instance. |
| 64 | * @return string Rendered block type output. |
| 65 | */ |
| 66 | protected function render_experimental_iapi_mini_cart_contents( $attributes, $content, $block ) { |
| 67 | $wrapper_attributes = get_block_wrapper_attributes( |
| 68 | array( |
| 69 | 'data-wp-interactive' => 'woocommerce/mini-cart-contents', |
| 70 | 'data-wp-style--background-color' => 'woocommerce/mini-cart::state.contentsBackgroundColor', |
| 71 | ) |
| 72 | ); |
| 73 | |
| 74 | ob_start(); |
| 75 | ?> |
| 76 | <div <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> |
| 77 | <div class="wc-block-components-drawer__close-wrapper"> |
| 78 | <button data-wp-on--click="woocommerce/mini-cart::actions.closeDrawer" class="wc-block-components-button wp-element-button wc-block-components-drawer__close contained" aria-label="Close" type="button"> |
| 79 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"> |
| 80 | <path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path> |
| 81 | </svg> |
| 82 | </button> |
| 83 | </div> |
| 84 | <?php |
| 85 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 86 | echo $content; |
| 87 | ?> |
| 88 | </div> |
| 89 | <?php |
| 90 | return ob_get_clean(); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Render the markup for the Mini-Cart Contents block. |
| 95 | * |
| 96 | * @param array $attributes Block attributes. |
| 97 | * @param string $content Block content. |
| 98 | * @param WP_Block $block Block instance. |
| 99 | * @return string Rendered block type output. |
| 100 | */ |
| 101 | protected function render( $attributes, $content, $block ) { |
| 102 | if ( is_admin() || WC()->is_rest_api_request() ) { |
| 103 | // In the editor we will display the placeholder, so no need to |
| 104 | // print the markup. |
| 105 | return ''; |
| 106 | } |
| 107 | |
| 108 | if ( Features::is_enabled( 'experimental-iapi-mini-cart' ) ) { |
| 109 | return $this->render_experimental_iapi_mini_cart_contents( $attributes, $content, $block ); |
| 110 | } |
| 111 | |
| 112 | return $content; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Enqueue frontend assets for this block, just in time for rendering. |
| 117 | * |
| 118 | * @param array $attributes Any attributes that currently are available from the block. |
| 119 | * @param string $content The block content. |
| 120 | * @param WP_Block $block The block object. |
| 121 | */ |
| 122 | protected function enqueue_assets( array $attributes, $content, $block ) { |
| 123 | parent::enqueue_assets( $attributes, $content, $block ); |
| 124 | $text_color = StyleAttributesUtils::get_text_color_class_and_style( $attributes ); |
| 125 | $bg_color = StyleAttributesUtils::get_background_color_class_and_style( $attributes ); |
| 126 | |
| 127 | $styles = array( |
| 128 | array( |
| 129 | 'selector' => array( |
| 130 | '.wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-mini-cart__footer-checkout', |
| 131 | '.wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-mini-cart__footer-checkout:hover', |
| 132 | '.wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-mini-cart__footer-checkout:focus', |
| 133 | '.wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-mini-cart__footer-cart.wc-block-components-button:hover', |
| 134 | '.wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-mini-cart__footer-cart.wc-block-components-button:focus', |
| 135 | '.wc-block-mini-cart__shopping-button a:hover', |
| 136 | '.wc-block-mini-cart__shopping-button a:focus', |
| 137 | ), |
| 138 | 'properties' => array( |
| 139 | array( |
| 140 | 'property' => 'color', |
| 141 | 'value' => $bg_color ? $bg_color['value'] : false, |
| 142 | ), |
| 143 | array( |
| 144 | 'property' => 'border-color', |
| 145 | 'value' => $text_color ? $text_color['value'] : false, |
| 146 | ), |
| 147 | array( |
| 148 | 'property' => 'background-color', |
| 149 | 'value' => $text_color ? $text_color['value'] : false, |
| 150 | ), |
| 151 | ), |
| 152 | ), |
| 153 | ); |
| 154 | |
| 155 | $parsed_style = sprintf( |
| 156 | ':root { --drawer-width: %s; --neg-drawer-width: calc(var(--drawer-width) * -1); }', |
| 157 | esc_html( $attributes['width'] ) |
| 158 | ); |
| 159 | |
| 160 | foreach ( $styles as $style ) { |
| 161 | $selector = is_array( $style['selector'] ) ? implode( ',', $style['selector'] ) : $style['selector']; |
| 162 | |
| 163 | $properties = array_filter( |
| 164 | $style['properties'], |
| 165 | function ( $property ) { |
| 166 | return $property['value']; |
| 167 | } |
| 168 | ); |
| 169 | |
| 170 | if ( ! empty( $properties ) ) { |
| 171 | $parsed_style .= $selector . '{'; |
| 172 | foreach ( $properties as $property ) { |
| 173 | $parsed_style .= sprintf( '%1$s:%2$s;', $property['property'], $property['value'] ); |
| 174 | } |
| 175 | $parsed_style .= '}'; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | wp_add_inline_style( |
| 180 | 'wc-blocks-style', |
| 181 | $parsed_style |
| 182 | ); |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Get list of Mini-Cart Contents block & its inner-block types. |
| 187 | * |
| 188 | * @return array; |
| 189 | */ |
| 190 | public static function get_mini_cart_block_types() { |
| 191 | $block_types = []; |
| 192 | |
| 193 | $block_types[] = 'MiniCartContents'; |
| 194 | $block_types[] = 'EmptyMiniCartContentsBlock'; |
| 195 | $block_types[] = 'FilledMiniCartContentsBlock'; |
| 196 | $block_types[] = 'MiniCartFooterBlock'; |
| 197 | $block_types[] = 'MiniCartItemsBlock'; |
| 198 | $block_types[] = 'MiniCartProductsTableBlock'; |
| 199 | $block_types[] = 'MiniCartShoppingButtonBlock'; |
| 200 | $block_types[] = 'MiniCartCartButtonBlock'; |
| 201 | $block_types[] = 'MiniCartCheckoutButtonBlock'; |
| 202 | $block_types[] = 'MiniCartTitleBlock'; |
| 203 | $block_types[] = 'MiniCartTitleItemsCounterBlock'; |
| 204 | $block_types[] = 'MiniCartTitleLabelBlock'; |
| 205 | |
| 206 | return $block_types; |
| 207 | } |
| 208 | } |
| 209 |