chore: update js logic for promo-code-form loader

feat/promo-code-loader
jatin 2024-11-25 18:00:14 +05:30
parent 80f866153c
commit bf315766d7
3 changed files with 484 additions and 236 deletions

View File

@ -398,3 +398,150 @@ $(function () {
return false;
});
});
$(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.on("submit", '[data-link-action="add-voucher"]', (e) => {
const promoSubmitBtn = $("#promo-code-form button");
e.preventDefault();
const n = $(e.currentTarget),
o = n.attr("action");
0 === n.find("[name=action]").length &&
n.append($("<input>", { type: "hidden", name: "ajax", value: 1 })),
0 === n.find("[name=action]").length &&
n.append(
$("<input>", { type: "hidden", name: "action", value: "update" }),
),
promoSubmitBtn.text("CHECKING");
promoSubmitBtn.prop("disable", true);
$.post(o, n.serialize(), null, "json")
.then((n) => {
n.hasError
? $(".js-error").show().find(".js-error-text").text(n.errors[0])
: prestashop.emit("updateCart", {
reason: e.target.dataset,
resp: n,
});
promoSubmitBtn.text("ADD");
promoSubmitBtn.prop("disable", false);
})
.fail((e) => {
prestashop.emit("handleError", {
eventType: "updateCart",
resp: e,
});
promoSubmitBtn.text("ADD");
promoSubmitBtn.prop("disable", false);
});
});
});

View File

@ -22,88 +22,89 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
import prestashop from 'prestashop';
import $ from 'jquery';
import prestashop from "prestashop";
import $ from "jquery";
const passwordPolicy = {
template: '#password-feedback',
hint: '.js-hint-password',
container: '.password-strength-feedback',
strengthText: '.password-strength-text',
requirementScore: '.password-requirements-score',
requirementLength: '.password-requirements-length',
requirementScoreIcon: '.password-requirements-score i',
requirementLengthIcon: '.password-requirements-length i',
progressBar: '.progress-bar',
inputColumn: '.js-input-column',
template: "#password-feedback",
hint: ".js-hint-password",
container: ".password-strength-feedback",
strengthText: ".password-strength-text",
requirementScore: ".password-requirements-score",
requirementLength: ".password-requirements-length",
requirementScoreIcon: ".password-requirements-score i",
requirementLengthIcon: ".password-requirements-length i",
progressBar: ".progress-bar",
inputColumn: ".js-input-column",
};
prestashop.themeSelectors = {
product: {
tabs: '.tabs .nav-link',
activeNavClass: 'js-product-nav-active',
activeTabClass: 'js-product-tab-active',
activeTabs: '.tabs .nav-link.active, .js-product-nav-active',
imagesModal: '.js-product-images-modal',
thumb: '.js-thumb',
thumbContainer: '.thumb-container, .js-thumb-container',
arrows: '.js-arrows',
selected: '.selected, .js-thumb-selected',
modalProductCover: '.js-modal-product-cover',
cover: '.js-qv-product-cover',
customizationModal: '.js-customization-modal',
tabs: ".tabs .nav-link",
activeNavClass: "js-product-nav-active",
activeTabClass: "js-product-tab-active",
activeTabs: ".tabs .nav-link.active, .js-product-nav-active",
imagesModal: ".js-product-images-modal",
thumb: ".js-thumb",
thumbContainer: ".thumb-container, .js-thumb-container",
arrows: ".js-arrows",
selected: ".selected, .js-thumb-selected",
modalProductCover: ".js-modal-product-cover",
cover: ".js-qv-product-cover",
customizationModal: ".js-customization-modal",
},
listing: {
searchFilterToggler: '#search_filter_toggler, .js-search-toggler',
searchFiltersWrapper: '#search_filters_wrapper',
searchFilterControls: '#search_filter_controls',
searchFilters: '#search_filters',
activeSearchFilters: '#js-active-search-filters',
listTop: '#js-product-list-top',
product: '.js-product',
list: '#js-product-list',
listBottom: '#js-product-list-bottom',
listHeader: '#js-product-list-header',
searchFiltersClearAll: '.js-search-filters-clear-all',
searchLink: '.js-search-link',
searchFilterToggler: "#search_filter_toggler, .js-search-toggler",
searchFiltersWrapper: "#search_filters_wrapper",
searchFilterControls: "#search_filter_controls",
searchFilters: "#search_filters",
activeSearchFilters: "#js-active-search-filters",
listTop: "#js-product-list-top",
product: ".js-product",
list: "#js-product-list",
listBottom: "#js-product-list-bottom",
listHeader: "#js-product-list-header",
searchFiltersClearAll: ".js-search-filters-clear-all",
searchLink: ".js-search-link",
},
order: {
returnForm: '#order-return-form, .js-order-return-form',
returnForm: "#order-return-form, .js-order-return-form",
},
arrowDown: '.arrow-down, .js-arrow-down',
arrowUp: '.arrow-up, .js-arrow-up',
clear: '.clear',
fileInput: '.js-file-input',
contentWrapper: '#content-wrapper, .js-content-wrapper',
footer: '#footer, .js-footer',
modalContent: '.js-modal-content',
modal: '#modal, .js-checkout-modal',
touchspin: '.js-touchspin',
arrowDown: ".arrow-down, .js-arrow-down",
arrowUp: ".arrow-up, .js-arrow-up",
clear: ".clear",
fileInput: ".js-file-input",
contentWrapper: "#content-wrapper, .js-content-wrapper",
footer: "#footer, .js-footer",
modalContent: ".js-modal-content",
modal: "#modal, .js-checkout-modal",
touchspin: ".js-touchspin",
checkout: {
termsLink: '.js-terms a',
giftCheckbox: '.js-gift-checkbox',
imagesLink: '.card-block .cart-summary-products p a, .js-show-details',
carrierExtraContent: '.carrier-extra-content, .js-carrier-extra-content',
btn: '.checkout a',
termsLink: ".js-terms a",
giftCheckbox: ".js-gift-checkbox",
imagesLink: ".card-block .cart-summary-products p a, .js-show-details",
carrierExtraContent: ".carrier-extra-content, .js-carrier-extra-content",
btn: ".checkout a",
},
cart: {
productLineQty: '.js-cart-line-product-quantity',
quickview: '.quickview',
touchspin: '.bootstrap-touchspin',
promoCode: '#promo-code',
displayPromo: '.display-promo',
promoCodeButton: '.promo-code-button',
discountCode: '.js-discount .code',
discountName: '[name=discount_name]',
actions: '[data-link-action="delete-from-cart"], [data-link-action="remove-voucher"]',
productLineQty: ".js-cart-line-product-quantity",
quickview: ".quickview",
touchspin: ".bootstrap-touchspin",
promoCode: "#promo-code",
displayPromo: ".display-promo",
promoCodeButton: ".promo-code-button",
discountCode: ".js-discount .code",
discountName: "[name=discount_name]",
actions:
'[data-link-action="delete-from-cart"], [data-link-action="remove-voucher"]',
},
notifications: {
dangerAlert: '#notifications article.alert-danger',
container: '#notifications .notifications-container',
dangerAlert: "#notifications article.alert-danger",
container: "#notifications .notifications-container",
},
passwordPolicy,
};
$(document).ready(() => {
prestashop.emit('themeSelectorsInit');
prestashop.emit("themeSelectorsInit");
});

File diff suppressed because one or more lines are too long