Created
July 2, 2024 18:09
-
-
Save unlocomqx/68d9fec1ac353afc30596b3626e83df6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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