Skip to content

Instantly share code, notes, and snippets.

@unlocomqx
Created July 2, 2024 18:09
Show Gist options
  • Save unlocomqx/68d9fec1ac353afc30596b3626e83df6 to your computer and use it in GitHub Desktop.
Save unlocomqx/68d9fec1ac353afc30596b3626e83df6 to your computer and use it in GitHub Desktop.
let reset_next = false // flag used to reset the quantity to the minimal quantity after adding to cart
document.addEventListener("dp-loaded", function () {
const addToCart = ceFrontend.utils.urlActions.actions.addToCart
ceFrontend.utils.urlActions.actions.addToCart = function (e) {
window.dpSaveCustomization().then(function (response) {
if (response) {
var id_customization = getFirstItem(response.id_customizations)
jQuery("[name=\"id_customization\"]").val(id_customization)
reset_next = true
addToCart({}, e)
}
})
}
prestashop.on("updatedProduct", updateAction)
updateAction()
function updateAction() {
window.jQuery("[href=\"#ce-action=addToCart{}\"]").attr("href", "#ce-action=dpAddToCart{}")
}
function getFirstItem(obj) {
var keys = Object.keys(obj)
if (!keys.length) {
return null
}
return obj[keys[0]]
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment