Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The modal "add to cart confirmation" should not displayed on error #41

Merged
merged 4 commits into from
Jul 18, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions ps_shoppingcart.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@ $(document).ready(function () {
function (event) {
var refreshURL = $('.blockcart').data('refresh-url');
var requestData = {};

if (event && event.reason) {
if (event && event.reason && !event.resp.hasError) {
requestData = {
id_product_attribute: event.reason.idProductAttribute,
id_product: event.reason.idProduct,
action: event.reason.linkAction
};
}

$.post(refreshURL, requestData).then(function (resp) {
$('.blockcart').replaceWith($(resp.preview).find('.blockcart'));
if (resp.modal) {
showModal(resp.modal);
}
}).fail(function (resp) {
prestashop.emit('handleError', {eventType: 'updateShoppingCart', resp: resp});
});
$.post(refreshURL, requestData).then(function (resp) {
$('.blockcart').replaceWith($(resp.preview).find('.blockcart'));
if (resp.modal) {
showModal(resp.modal);
}
}).fail(function (resp) {
prestashop.emit('handleError', { eventType: 'updateShoppingCart', resp: resp });
});
}
if (event && event.resp && event.resp.hasError) {
$('#product-availability').html('<i class="material-icons product-unavailable">&#xE14B;</i>' + event.resp.errors.join('<br/>'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not good to inject this HTML here as

  • it mixes JS and HTML, that can make the code hard to debug and maintain
  • if the product page styling is modified, this code will need to be modified accordingly (and I'm sure we will forget)

However I understand that this is the only way because there is not better way available.

What about we provide a better way in the Core ? Maybe a JS function displayErrorMessageUnderAddToCartButton(errorMessage) ? This would be an available function in Classic Theme, and it could be called by modules (here, by ps_shoppingcart).

Any feedback @Quetzacoalt91 @eternoendless ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it's the only way without impact on PS core,
The html part just add a material icon, it's not dependant on the product page styling.

Please notice that the add to cart ajax call can return more than one error.

Disabling the add to cart button is releveant in out of stock product but what about adding extra stok quantity ? The button souldn'nt not be desabled if asked quantity is above stock.

}
}
);
});
Expand Down