fix: reflect the changes on cart update

pagebuilder
Dinesh Salunke 2023-12-05 18:49:29 +05:30
parent 599e9fafb8
commit 2f71a0f0d7
2 changed files with 78 additions and 5 deletions

View File

@ -162,4 +162,46 @@ $(function () {
};
$(".th-accordion").thaccordion();
prestashop.blockcart = prestashop.blockcart || {};
var showModal = prestashop.blockcart.showModal || function(modal) {
var $body = $('body');
$body.append(modal);
$body.one('click', '#blockcart-modal', function(event) {
if (event.target.id === 'blockcart-modal') {
$(event.target).remove()
}
})
}
;
prestashop.on('updateCart', function(event) {
var refreshURL = $('.blockcart').data('refresh-url');
var requestData = {};
if (event && event.reason && typeof event.resp !== 'undefined' && !event.resp.hasError) {
requestData = {
id_customization: event.reason.idCustomization,
id_product_attribute: event.reason.idProductAttribute,
id_product: event.reason.idProduct,
action: event.reason.linkAction
}
}
if (event && event.resp && event.resp.hasError) {
prestashop.emit('showErrorNextToAddtoCartButton', {
errorMessage: event.resp.errors.join('<br/>')
})
}
$.post(refreshURL, requestData).then(function(resp) {
// TODO: keeping this over here, for later purposes if need be
// var html = $('<div />').append($.parseHTML(resp.preview));
// $('.blockcart').replaceWith($(resp.preview).find('.blockcart'));
// if (resp.modal) {
// showModal(resp.modal)
// }
}).fail(function(resp) {
prestashop.emit('handleError', {
eventType: 'updateShoppingCart',
resp: resp
})
})
})
});

File diff suppressed because one or more lines are too long