How to prevent Added to cart popup when we submit any form in pdp page

Scenario: When we submit some forms which are in pdp page the added to cart popup will come, we can prevent that by this solution.

JAVASCRIPT:

Entrypoint:

_.extend(CartAddToCartButtonView.prototype, {
                    events: _.extend({}, CartAddToCartButtonView.prototype.events,{
                        'mouseup [data-type="add-to-cart"]': 'addToCart',
                        'click [data-type="add-to-cart"]': 'addToCart'
                    }),
                    addToCart: function(e) {
                        try {
                            this.model.isValid('custcol_ag_checkcolors');
                            var isPersonaizable, isPersonalized, isConformedData; 
    
                            if (this.model.get('custcol_ag_havepersonalization') === 'T') {
                                isPersonaizable = true;
                            }
                            if (isPersonaizable) {
                                isPersonalized = $('#personalize-checkbox')[0].checked;
                                isConformedData = $('#personalized-checkbox')[0].checked;
                                if (isPersonalized && isConformedData) {
                                    this.newAddToCart(e);
                                }else{
                                    return false;
                                }
                            } else {
                                this.newAddToCart(e);
                            }
                        } catch (error) {
                            
                        }
                    },
                    newAddToCart: function newAddToCart(e) {
                        var t = this;
                        try {
                            setTimeout(function() {
                                for (var e = 0; e < document.getElementsByClassName("bx-pager-link").length; e++) {
                                    var t = document.getElementsByClassName("bx-pager-link")[e].children[0].currentSrc.split("?")[0]
                                      , i = document.getElementsByClassName("product-details-image-gallery-container")[e + 1].innerHTML.split(" ")
                                      , n = i[1].split("?");
                                    n[0] != 'src="' + t && (n[0] = "src=" + t,
                                    i[1] = n.join("?"),
                                    i = i.join(" "),
                                    document.getElementsByClassName("product-details-image-gallery-container")[e + 1].innerHTML = i)
                                }
                            }, 3e3)
                        } catch (e) {
                            console.warn("The Zoom bug fix is throwing an error (Cart.AddToCart.Button.View): " + JSON.stringify(e))
                        }
                        e.preventDefault();
                        var i, n, r, o, a, s = this;
                        if (this.model.areAttributesValid(["options", "quantity"], s.getAddToCartValidators()))
                            return this.model.isNew() || "cart" !== this.model.get("source") ? (i = u.createFromProduct(this.model),
                            n = c.itemToTrack(i),
                            r = l.Loggers.getLogger(),
                            o = r.start("Add to Cart"),
                            (a = this.cart.addLine(i)).then(function() {
                                var e = c.getAddToCartOperationId(t.cart.get("lines").models, i);
                                r.end(o, {
                                    operationIds: e,
                                    status: "success",
                                    itemId: n.itemId,
                                    itemQuantity: n.itemQuantity
                                })
                            }),
                            d.showCartConfirmation(a, i, s.options.application)) : (a = this.cart.updateProduct(this.model)).done(function() {
                                s.options.application.getLayout().closeModal()
                            }),
                            a.fail(function(e) {
                                var t = null;
                                try {
                                    e && e.responseText && (t = JSON.parse(e.responseText).errorDetails)
                                } catch (e) {
                                    console.error(e)
                                } finally {
                                    t && "LINE_ROLLBACK" === t.status && s.model.set("internalid", t.newLineId)
                                }
                            }),
                            this.disableElementsOnPromise(a, e.target),
                            !1
                    },
                    getContext: _.wrap(CartAddToCartButtonView.prototype.getContext, function (fn) {
                        var originalRet = fn.apply(this, _.toArray(arguments).slice(1));
                        
                        originalRet.addtoCartDisable = this.model.attributes.item.attributes.custitem_tag_show_liquid_pixels
                        return originalRet;
                    })
                });

Leave a comment

Your email address will not be published. Required fields are marked *