fix: only keep overrider logic for promo code form

fixes add to cart sending two requests instead of one
bug-new
jatin 2024-11-26 15:14:58 +05:30
parent 6489d8516c
commit 23daeb6e32
2 changed files with 175 additions and 357 deletions

View File

@ -400,117 +400,8 @@ $(function () {
});
$(document).ready(() => {
prestashop.on("updateCart", (e) => {
prestashop.cart = e.resp.cart;
const n = $(".js-cart").data("refresh-url");
if (!n) return;
let o = {};
e &&
e.reason &&
(o = {
id_product_attribute: e.reason.idProductAttribute,
id_product: e.reason.idProduct,
}),
$.post(n, o)
.then((e) => {
$(prestashop.selectors.cart.detailedTotals).replaceWith(
e.cart_detailed_totals,
),
$(prestashop.selectors.cart.summaryItemsSubtotal).replaceWith(
e.cart_summary_items_subtotal,
),
$(prestashop.selectors.cart.summarySubTotalsContainer).replaceWith(
e.cart_summary_subtotals_container,
),
$(prestashop.selectors.cart.summaryProducts).replaceWith(
e.cart_summary_products,
),
$(prestashop.selectors.cart.summaryTotals).replaceWith(
e.cart_summary_totals,
),
$(prestashop.selectors.cart.detailedActions).replaceWith(
e.cart_detailed_actions,
),
$(prestashop.selectors.cart.voucher).replaceWith(e.cart_voucher),
$(prestashop.selectors.cart.overview).replaceWith(e.cart_detailed),
$(prestashop.selectors.cart.summaryTop).replaceWith(
e.cart_summary_top,
),
$(prestashop.selectors.cart.productCustomizationId).val(0),
$(prestashop.selectors.cart.lineProductQuantity).each((e, n) => {
const r = $(n);
r.attr("value", r.val());
}),
$(prestashop.selectors.checkout.cartPaymentStepRefresh).length &&
i(),
prestashop.emit("updatedCart", {
eventType: "updateCart",
resp: e,
});
})
.fail((e) => {
prestashop.emit("handleError", { eventType: "updateCart", resp: e });
});
});
const e = $("body");
e.on("click", '[data-button-action="add-to-cart"]', (e) => {
e.preventDefaul$;
const n = $(e.currentTarget.form),
o = `${n.serialize()}&add=1&action=update`,
i = n.attr("action"),
a = $(e.currentTarget);
a.prop("disabled", !0);
let s = (e) => {
e
.parents(prestashop.selectors.product.addToCart)
.firs$.find(prestashop.selectors.product.minimalQuantity)
.addClass("error"),
e.paren$.find("label").addClass("error");
};
const c = n.find("input[min]");
((e) => {
let n = !0;
return (
e.each((e, r) => {
const o = $(r),
i = parseInt(o.attr("min"), 10);
i && o.val() < i && (s(o), (n = !1));
}),
n
);
})(c)
? $.post(i, o, null, "json")
.then((e) => {
e.hasError
? prestashop.emit("handleError", {
eventType: "addProductToCart",
resp: e,
})
: prestashop.emit("updateCart", {
reason: {
idProduct: e.id_product,
idProductAttribute: e.id_product_attribute,
idCustomization: e.id_customization,
linkAction: "add-to-cart",
cart: e.cart,
},
resp: e,
});
})
.fail((e) => {
prestashop.emit("handleError", {
eventType: "addProductToCart",
resp: e,
});
})
.always(() => {
setTimeout(() => {
a.prop("disabled", !1);
}, 1e3);
})
: s(c);
}),
e.off("submit", '[data-link-action="add-voucher"]'),
e.off("submit", '[data-link-action="add-voucher"]'),
e.on("submit", '[data-link-action="add-voucher"]', (e) => {
const promoSubmitBtn = $("#promo-code-form button");
e.preventDefault();

File diff suppressed because one or more lines are too long