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