From c58b0cf93665681571ec96ce12bfecbdaa909ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Fri, 29 Dec 2023 17:23:35 +0100 Subject: [PATCH] Fix error when adding to cart from the Product Collection block if Google Analytics plugin is enabled (II) (#43177) * Revert "Trigger event `experimental__woocommerce_blocks-cart-add-item` in the SSR Product Button vis Interactivity API (#42946)" This reverts commit 4fec136da1e08b3fbbbf0e9d01cf7fab71be5c46. * Add changefile(s) from automation for the following project(s): woocommerce-blocks --------- Co-authored-by: github-actions --- .../blocks/product-elements/button/frontend.tsx | 11 ----------- .../43177-fix-add-to-cart-google-analytics-error-ii | 4 ++++ 2 files changed, 4 insertions(+), 11 deletions(-) create mode 100644 plugins/woocommerce/changelog/43177-fix-add-to-cart-google-analytics-error-ii diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/button/frontend.tsx b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/button/frontend.tsx index a23d242bbe4..3086aee599e 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/button/frontend.tsx +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/button/frontend.tsx @@ -7,7 +7,6 @@ import { CART_STORE_KEY as storeKey } from '@woocommerce/block-data'; import { Cart } from '@woocommerce/type-defs/cart'; import { createRoot } from '@wordpress/element'; import NoticeBanner from '@woocommerce/base-components/notice-banner'; -import { doAction } from '@wordpress/hooks'; interface Context { isLoading: boolean; @@ -136,7 +135,6 @@ const { state } = store< Store >( 'woocommerce/product-button', { *addToCart() { const context = getContext(); const { productId, quantityToAdd } = context; - const product = getProductById( state.cart, productId ); context.isLoading = true; @@ -146,15 +144,6 @@ const { state } = store< Store >( 'woocommerce/product-button', { quantityToAdd ); - // Adding a manual trigger of the event for backward compatibility - // and symmetry ("remove" event is triggered properly from Cart and Mini Cart). - // The events will be revisited and unified in scope of: - // https://github.com/woocommerce/woocommerce/pull/42946 - yield doAction( - `experimental__woocommerce_blocks-cart-add-item`, - product - ); - // After the cart is updated, sync the temporary number of items again. context.temporaryNumberOfItems = state.numberOfItemsInTheCart; } catch ( error ) { diff --git a/plugins/woocommerce/changelog/43177-fix-add-to-cart-google-analytics-error-ii b/plugins/woocommerce/changelog/43177-fix-add-to-cart-google-analytics-error-ii new file mode 100644 index 00000000000..96bf9372fd9 --- /dev/null +++ b/plugins/woocommerce/changelog/43177-fix-add-to-cart-google-analytics-error-ii @@ -0,0 +1,4 @@ +Significance: patch +Type: fix +Comment: Product Button: remove the `experimental__woocommerce_blocks-cart-add-item` event to avoid conflicts with extensions. +