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1 year ago AddToCartWithOptions 5 days ago OrderConfirmation 2 months ago ProductCollection 5 days ago Reviews 2 months ago AbstractBlock.php 5 days ago AbstractDynamicBlock.php 2 years ago AbstractInnerBlock.php 1 year ago AbstractProductGrid.php 3 months ago ActiveFilters.php 2 years ago AddToCartForm.php 1 month ago AddToWishlistButton.php 1 month ago AllProducts.php 5 days ago AllReviews.php 2 years ago AtomicBlock.php 2 years ago AttributeFilter.php 1 year ago Breadcrumbs.php 5 days ago Cart.php 5 days 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 1 month ago CategoryDescription.php 2 months ago CategoryTitle.php 2 months ago Checkout.php 5 days 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 5 days 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 5 days ago MiniCartCartButtonBlock.php 11 months ago MiniCartCheckoutButtonBlock.php 11 months ago MiniCartContents.php 3 months ago MiniCartFooterBlock.php 5 days ago MiniCartItemsBlock.php 11 months ago MiniCartProductsTableBlock.php 5 days 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 5 days ago ProductCategories.php 1 month ago ProductCategory.php 2 years ago ProductDescription.php 9 months ago ProductDetails.php 5 months ago ProductFilterActive.php 1 month ago ProductFilterAttribute.php 5 days ago ProductFilterCheckboxList.php 1 month ago ProductFilterChips.php 1 month ago ProductFilterClearButton.php 1 month ago ProductFilterPrice.php 1 month ago ProductFilterPriceSlider.php 1 month ago ProductFilterRating.php 1 month ago ProductFilterRemovableChips.php 1 month ago ProductFilterStatus.php 5 days ago ProductFilterTaxonomy.php 5 days ago ProductFilters.php 5 days ago ProductGallery.php 1 month ago ProductGalleryLargeImage.php 1 month ago ProductGalleryThumbnails.php 1 month ago ProductImage.php 5 days ago ProductImageGallery.php 8 months ago ProductMeta.php 1 year ago ProductNew.php 2 years ago ProductOnSale.php 2 years ago ProductPrice.php 2 months ago ProductQuery.php 5 days 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 5 days 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 1 month ago SingleProduct.php 2 months ago StockFilter.php 2 years ago StoreNotices.php 1 year ago Wishlist.php 1 month ago
Cart.php
349 lines
1 <?php
2 namespace Automattic\WooCommerce\Blocks\BlockTypes;
3
4 use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;
5 use Automattic\WooCommerce\Enums\TaxDisplayMode;
6
7 /**
8 * Cart class.
9 *
10 * @internal
11 */
12 class Cart extends AbstractBlock {
13 /**
14 * Block name.
15 *
16 * @var string
17 */
18 protected $block_name = 'cart';
19
20 /**
21 * Chunks build folder.
22 *
23 * @var string
24 */
25 protected $chunks_folder = 'cart-blocks';
26
27 /**
28 * Initialize this block type.
29 *
30 * - Hook into WP lifecycle.
31 * - Register the block with WordPress.
32 */
33 protected function initialize() {
34 parent::initialize();
35 add_action( 'wp_loaded', array( $this, 'register_patterns' ) );
36 add_action( 'wp', array( $this, 'disable_wp_emoji' ) );
37 }
38
39 /**
40 * Remove WordPress emoji detection script on pages containing this block.
41 *
42 * The wp-emoji MutationObserver converts emoji text nodes to <img> elements
43 * when React hydrates or re-renders, corrupting the DOM tree and crashing the block.
44 * The wp-exclude-emoji class on the wrapper only prevents the initial parse, not the
45 * MutationObserver, so the script must be removed entirely.
46 *
47 * @since 10.8.0
48 *
49 * @return void
50 */
51 public function disable_wp_emoji() {
52 if ( has_block( $this->get_full_block_name() ) ) {
53 remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
54 remove_action( 'wp_print_styles', 'print_emoji_styles' );
55 }
56 }
57
58 /**
59 * Dequeues the scripts added by WC Core to the Cart page.
60 *
61 * @return void
62 */
63 public function dequeue_woocommerce_core_scripts() {
64 wp_dequeue_script( 'wc-cart' );
65 wp_dequeue_script( 'wc-password-strength-meter' );
66 wp_dequeue_script( 'selectWoo' );
67 wp_dequeue_style( 'select2' );
68 }
69
70 /**
71 * Register block pattern for Empty Cart Message to make it translatable.
72 */
73 public function register_patterns() {
74 $shop_permalink = wc_get_page_permalink( 'shop' );
75
76 register_block_pattern(
77 'woocommerce/cart-heading',
78 array(
79 'title' => '',
80 'inserter' => false,
81 'content' => '<!-- wp:heading {"align":"wide", "level":1} --><h1 class="wp-block-heading alignwide">' . esc_html__( 'Cart', 'woocommerce' ) . '</h1><!-- /wp:heading -->',
82 )
83 );
84 register_block_pattern(
85 'woocommerce/cart-cross-sells-message',
86 array(
87 'title' => '',
88 'inserter' => false,
89 'content' => '<!-- wp:heading {"fontSize":"large"} --><h2 class="wp-block-heading has-large-font-size">' . esc_html__( 'You may be interested in…', 'woocommerce' ) . '</h2><!-- /wp:heading -->',
90 )
91 );
92 register_block_pattern(
93 'woocommerce/cart-empty-message',
94 array(
95 'title' => '',
96 'inserter' => false,
97 'content' => '
98 <!-- wp:heading {"textAlign":"center","className":"with-empty-cart-icon wc-block-cart__empty-cart__title"} --><h2 class="wp-block-heading has-text-align-center with-empty-cart-icon wc-block-cart__empty-cart__title">' . esc_html__( 'Your cart is currently empty!', 'woocommerce' ) . '</h2><!-- /wp:heading -->
99 <!-- wp:paragraph {"align":"center"} --><p class="has-text-align-center"><a href="' . esc_attr( esc_url( $shop_permalink ) ) . '">' . esc_html__( 'Browse store', 'woocommerce' ) . '</a></p><!-- /wp:paragraph -->
100 ',
101 )
102 );
103 register_block_pattern(
104 'woocommerce/cart-new-in-store-message',
105 array(
106 'title' => '',
107 'inserter' => false,
108 'content' => '<!-- wp:heading {"textAlign":"center"} --><h2 class="wp-block-heading has-text-align-center">' . esc_html__( 'New in store', 'woocommerce' ) . '</h2><!-- /wp:heading -->',
109 )
110 );
111 }
112
113 /**
114 * Get the editor script handle for this block type.
115 *
116 * @param string $key Data to get, or default to everything.
117 * @return array|string;
118 */
119 protected function get_block_type_editor_script( $key = null ) {
120 $script = [
121 'handle' => 'wc-' . $this->block_name . '-block',
122 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ),
123 'dependencies' => [ 'wc-blocks' ],
124 ];
125 return $key ? $script[ $key ] : $script;
126 }
127
128 /**
129 * Get the frontend script handle for this block type.
130 *
131 * @see $this->register_block_type()
132 * @param string $key Data to get, or default to everything.
133 * @return array|string
134 */
135 protected function get_block_type_script( $key = null ) {
136 $script = [
137 'handle' => 'wc-' . $this->block_name . '-block-frontend',
138 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name . '-frontend' ),
139 'dependencies' => [],
140 ];
141 return $key ? $script[ $key ] : $script;
142 }
143
144 /**
145 * Get the frontend style handle for this block type.
146 *
147 * @return string[]
148 */
149 protected function get_block_type_style() {
150 return array_merge( parent::get_block_type_style(), [ 'wc-blocks-packages-style' ] );
151 }
152
153 /**
154 * Enqueue frontend assets for this block, just in time for rendering.
155 *
156 * @param array $attributes Any attributes that currently are available from the block.
157 * @param string $content The block content.
158 * @param WP_Block $block The block object.
159 */
160 protected function enqueue_assets( array $attributes, $content, $block ) {
161 /**
162 * Fires before cart block scripts are enqueued.
163 *
164 * @since 2.6.0
165 */
166 do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_before' );
167 parent::enqueue_assets( $attributes, $content, $block );
168 /**
169 * Fires after cart block scripts are enqueued.
170 *
171 * @since 2.6.0
172 */
173 do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_after' );
174 }
175
176 /**
177 * Append frontend scripts when rendering the Cart block.
178 *
179 * @param array $attributes Block attributes.
180 * @param string $content Block content.
181 * @param WP_Block $block Block instance.
182 * @return string Rendered block type output.
183 */
184 protected function render( $attributes, $content, $block ) {
185 // Dequeue the core scripts when rendering this block.
186 add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_woocommerce_core_scripts' ), 20 );
187
188 /**
189 * We need to check if $content has any templates from prior iterations of the block, in order to update to the latest iteration.
190 * We test the iteration version by searching for new blocks brought in by it.
191 * The blocks used for testing should be always available in the block (not removable by the user).
192 */
193
194 $regex_for_filled_cart_block = '/<div[^<]*?data-block-name="woocommerce\/filled-cart-block"[^>]*?>/mi';
195 // Filled Cart block was added in i2, so we search for it to see if we have a Cart i1 template.
196 $has_i1_template = ! preg_match( $regex_for_filled_cart_block, $content );
197
198 if ( $has_i1_template ) {
199 /**
200 * This fallback structure needs to match the defaultTemplate variables defined in the block's edit.tsx files,
201 * starting from the parent block and going down each inner block, in the order the blocks were registered.
202 */
203 $inner_blocks_html = '$0
204 <div data-block-name="woocommerce/filled-cart-block" class="wp-block-woocommerce-filled-cart-block">
205 <div data-block-name="woocommerce/cart-items-block" class="wp-block-woocommerce-cart-items-block">
206 <div data-block-name="woocommerce/cart-line-items-block" class="wp-block-woocommerce-cart-line-items-block"></div>
207 </div>
208 <div data-block-name="woocommerce/cart-totals-block" class="wp-block-woocommerce-cart-totals-block">
209 <div data-block-name="woocommerce/cart-order-summary-block" class="wp-block-woocommerce-cart-order-summary-block"></div>
210 <div data-block-name="woocommerce/cart-express-payment-block" class="wp-block-woocommerce-cart-express-payment-block"></div>
211 <div data-block-name="woocommerce/proceed-to-checkout-block" class="wp-block-woocommerce-proceed-to-checkout-block"></div>
212 <div data-block-name="woocommerce/cart-accepted-payment-methods-block" class="wp-block-woocommerce-cart-accepted-payment-methods-block"></div>
213 </div>
214 </div>
215 <div data-block-name="woocommerce/empty-cart-block" class="wp-block-woocommerce-empty-cart-block">
216 ';
217
218 $content = preg_replace( '/<div class="[a-zA-Z0-9_\- ]*wp-block-woocommerce-cart[a-zA-Z0-9_\- ]*">/mi', $inner_blocks_html, $content );
219 $content = $content . '</div>';
220 }
221
222 /**
223 * Cart i3 added inner blocks for Order summary. We need to add them to Cart i2 templates.
224 * The order needs to match the order in which these blocks were registered.
225 */
226 $order_summary_with_inner_blocks = '$0
227 <div data-block-name="woocommerce/cart-order-summary-heading-block" class="wp-block-woocommerce-cart-order-summary-heading-block"></div>
228 <div data-block-name="woocommerce/cart-order-summary-subtotal-block" class="wp-block-woocommerce-cart-order-summary-subtotal-block"></div>
229 <div data-block-name="woocommerce/cart-order-summary-fee-block" class="wp-block-woocommerce-cart-order-summary-fee-block"></div>
230 <div data-block-name="woocommerce/cart-order-summary-discount-block" class="wp-block-woocommerce-cart-order-summary-discount-block"></div>
231 <div data-block-name="woocommerce/cart-order-summary-coupon-form-block" class="wp-block-woocommerce-cart-order-summary-coupon-form-block"></div>
232 <div data-block-name="woocommerce/cart-order-summary-shipping-form-block" class="wp-block-woocommerce-cart-order-summary-shipping-block"></div>
233 <div data-block-name="woocommerce/cart-order-summary-taxes-block" class="wp-block-woocommerce-cart-order-summary-taxes-block"></div>
234 ';
235 // Order summary subtotal block was added in i3, so we search for it to see if we have a Cart i2 template.
236 $regex_for_order_summary_subtotal = '/<div[^<]*?data-block-name="woocommerce\/cart-order-summary-subtotal-block"[^>]*?>/mi';
237 $regex_for_order_summary = '/<div[^<]*?data-block-name="woocommerce\/cart-order-summary-block"[^>]*?>/mi';
238 $has_i2_template = ! preg_match( $regex_for_order_summary_subtotal, $content );
239
240 if ( $has_i2_template ) {
241 $content = preg_replace( $regex_for_order_summary, $order_summary_with_inner_blocks, $content );
242 }
243
244 return $content;
245 }
246
247 /**
248 * Extra data passed through from server to client for block.
249 *
250 * @param array $attributes Any attributes that currently are available from the block.
251 * Note, this will be empty in the editor context when the block is
252 * not in the post content on editor load.
253 */
254 protected function enqueue_data( array $attributes = [] ) {
255 parent::enqueue_data( $attributes );
256
257 $this->asset_data_registry->add( 'countryData', CartCheckoutUtils::get_country_data() );
258 $this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ) );
259 $this->asset_data_registry->add( 'displayCartPricesIncludingTax', TaxDisplayMode::INCLUSIVE === get_option( 'woocommerce_tax_display_cart' ) );
260 $this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled() );
261 $this->asset_data_registry->add( 'couponsEnabled', wc_coupons_enabled() );
262 $this->asset_data_registry->add( 'shippingEnabled', wc_shipping_enabled() );
263 $this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ) );
264 $this->asset_data_registry->register_page_id( isset( $attributes['checkoutPageId'] ) ? $attributes['checkoutPageId'] : 0 );
265 $this->asset_data_registry->add( 'isBlockTheme', wp_is_block_theme() );
266 $this->asset_data_registry->add( 'shippingMethodsExist', CartCheckoutUtils::shipping_methods_exist() > 0 );
267
268 $is_block_editor = $this->is_block_editor();
269
270 // Check `current_user_can` so we can show notices about incompatible extensions in the front-end to admins too.
271 if ( ( $is_block_editor || current_user_can( 'manage_woocommerce' ) ) && ! $this->asset_data_registry->exists( 'incompatibleExtensions' ) ) {
272 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && function_exists( 'get_plugins' ) ) {
273 $declared_extensions = \Automattic\WooCommerce\Utilities\FeaturesUtil::get_compatible_plugins_for_feature( 'cart_checkout_blocks' );
274 $all_plugins = \get_plugins();
275 $incompatible_extensions = array_reduce(
276 $declared_extensions['incompatible'],
277 function ( array $acc, $item ) use ( $all_plugins ) {
278 $plugin = $all_plugins[ $item ] ?? null;
279 $plugin_id = $plugin['TextDomain'] ?? dirname( $item );
280 $plugin_name = $plugin['Name'] ?? $plugin_id;
281 $acc[] = [
282 'id' => $plugin_id,
283 'title' => $plugin_name,
284 ];
285 return $acc;
286 },
287 []
288 );
289 $this->asset_data_registry->add( 'incompatibleExtensions', $incompatible_extensions );
290 }
291 }
292
293 // Hydrate the following data depending on admin or frontend context.
294 if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
295 $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' );
296 }
297
298 /**
299 * Fires after cart block data is registered.
300 *
301 * @since 2.6.0
302 */
303 do_action( 'woocommerce_blocks_cart_enqueue_data' );
304 }
305
306 /**
307 * Register script and style assets for the block type before it is registered.
308 *
309 * This registers the scripts; it does not enqueue them.
310 */
311 protected function register_block_type_assets() {
312 parent::register_block_type_assets();
313 $chunks = $this->get_chunks_paths( $this->chunks_folder );
314 $vendor_chunks = $this->get_chunks_paths( 'vendors--cart-blocks' );
315 $shared_chunks = [];
316 $this->register_chunk_translations( array_merge( $chunks, $vendor_chunks, $shared_chunks ) );
317 }
318
319 /**
320 * Get list of Cart block & its inner-block types.
321 *
322 * @return array;
323 */
324 public static function get_cart_block_types() {
325 return [
326 'Cart',
327 'CartOrderSummaryTaxesBlock',
328 'CartOrderSummarySubtotalBlock',
329 'CartOrderSummaryTotalsBlock',
330 'FilledCartBlock',
331 'EmptyCartBlock',
332 'CartTotalsBlock',
333 'CartItemsBlock',
334 'CartLineItemsBlock',
335 'CartOrderSummaryBlock',
336 'CartExpressPaymentBlock',
337 'ProceedToCheckoutBlock',
338 'CartAcceptedPaymentMethodsBlock',
339 'CartOrderSummaryCouponFormBlock',
340 'CartOrderSummaryDiscountBlock',
341 'CartOrderSummaryFeeBlock',
342 'CartOrderSummaryHeadingBlock',
343 'CartOrderSummaryShippingBlock',
344 'CartCrossSellsBlock',
345 'CartCrossSellsProductsBlock',
346 ];
347 }
348 }
349