Search

Mar 28, 2023

Magento 2.3.3 Bug Javascript on Google Tag Manager module

We are using Google tag manager and got a bug on product detail page. After click add to cart button, the mini cart didn't update qty. The main reason is by google tag manager js. 


Step by step:

1. Go to detail page

2. Choose Color, Size and click add to cart 

3. Item is added but the mini cart didn't update qty 

4. Open web console log via F12 button and saw javascript error Uncaught TypeError: Cannot read property 'forEach' of undefined at the file /Magento_GoogleTagManager/js/google-tag-manager-cart.js


SOLUTION:

Please follow the patch file

diff --git a/vendor/magento/module-google-tag-manager/view/frontend/web/js/google-tag-manager-cart.js b/vendor/magento/module-google-tag-manager/view/frontend/web/js/google-tag-manager-cart.js
index 2d6e9ac7..2a9c115b 100644
--- a/vendor/magento/module-google-tag-manager/view/frontend/web/js/google-tag-manager-cart.js
+++ b/vendor/magento/module-google-tag-manager/view/frontend/web/js/google-tag-manager-cart.js
@@ -172,15 +172,17 @@ define([
             var product;

             this.options.temporaryEventStorage.forEach(function (item, index) {
-                item.productIds.forEach(function (productId) {
-                    product = this.getProductById(productId);
+                if (item.productIds) {
+                    item.productIds.forEach(function (productId) {
+                        product = this.getProductById(productId);

-                    if (!_.isUndefined(product['product_sku']) && parseInt(product.qty, 10) > 0) {
-                        this.options.actions[item.type](product);
-                    }
+                        if (!_.isUndefined(product['product_sku']) && parseInt(product.qty, 10) > 0) {
+                            this.options.actions[item.type](product);
+                        }

-                    this.options.temporaryEventStorage.splice(index, 1);
-                }.bind(this));
+                        this.options.temporaryEventStorage.splice(index, 1);
+                    }.bind(this));
+                }
             }.bind(this));
         },

No comments:

Post a Comment