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
Conversation
…uest return an error I've juste added a test to disable launching of showModal if the add to cart request (event) return an error.
Looks good 👍 do you have examples of errors that still open the modal ? Maybe we should notify the customer that something wrong happened, but it depends of what went wrong. If the server failed to answer the request, I guess in debug mode we should display the error, else only say something like "an error happened, please try again". If however it's a valid reason like "sorry ! someone else got the last item, this product is now out of stock !" we can always display the error message. What do you think ? |
|
Thank you for your issue but it's a duplicate of: PrestaShop/PrestaShop#11631 so I close it. |
Oops, sorry I was a little too fast and didn't see that is a PR :) |
OK thanks @marionf to keep it open, it's a major issue for me. |
I just tested your PR The modal isn't displayed anymore if the product is out of stock and the product page is not refreshed. Video: https://drive.google.com/file/d/1HF5gts5RwANbmQ4zeTWCr38wao0lsSbg/view?usp=sharing |
It's not what I have but I'm not in 1.7.6. Have you checked that the ajax cart controller call returns an error ? |
@marionf I've installed the develop branch and tested my pr : |
I well have the error and no modals when the product is out of stock, but it's still added to the cart We would like, like describe here, display the out of stock message when you click on "add to cart" and the product shouldn't be added to the cart. Do you think that you could improve your PR this way ? |
I've posted another issue : the out of stock product shouldn't be added to the cart : PrestaShop/PrestaShop#13374 |
@marionf I'll try to improve it to match @colinegin idea PrestaShop/PrestaShop#11631 (comment) |
As suggested by @colinegin the errors are now diplayed under the add to cart button : PrestaShop/PrestaShop#11631 (comment)
@marionf I've just commited the improvement. |
Thank you for this improvement @jf-viguier Do you think it's possible to display the "label of out of stock products with denied backorders" instead and disable the add to cart button ? |
It's already like this if you load the page without stock. My PR simply display the error returned by the add to stock ajax request (it was like that in 1.6). |
@marionf This PR will display the error message returned by prestashop when the "add to cart" fails. So if we want to display the label of "out of stock products with denied backorders", we need prestashop to return this label in the error message, and this should do the job. I think this needs a modification in the Core 🤔, doesn't it @jf-viguier ? About This topic is borderline anyways 😅 |
ps_shoppingcart.js
Outdated
}); | ||
} | ||
if (event && event.resp && event.resp.hasError) { | ||
$('#product-availability').html('<i class="material-icons product-unavailable"></i>' + event.resp.errors.join('<br/>')); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
This error message is too long for the product page, that's why we would like to display the out of stock message and disable the add to cart button. If a PR on the core is needed, I can validate this one but we should do the other PR before releasing the new version of ps_shoppingcart |
Check that event.resp exists before testing event.resp.hasError. This fix is required for deletint product in cart
Sorry for the wait @jf-viguier @marionf, we got very busy with the 1.7.6 beta 😄 So, in order to sum it up, here's what I suggest:
When this PR is done and merged, we can update @jf-viguier PR to use *To do so I have to check how current JS functions provided by the theme work. It might require to create a new custom prestashop event to be emitted by module. I'd like a confirmation that this looks suitable indeed @Quetzacoalt91 (as I have never updated the Core theme before) ? |
It's sound good to be, thanks |
I made PR PrestaShop/PrestaShop#14033 to provide a new FO prestashop event "showErrorNextToAddtoCartButton" that you use to display an error message next to "add to cart" button:
So we can avoid modifying html directly @marionf I'm wondering if we should really use "label of out of stock products with denied backorders" message here. This message is intended to be displayed to say something like "out of stock, sorry come back later". Right now the message being returned is "The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted." |
Another thing: if we introduce and use this new JS event, then next version of ps_shoppingcart will only work with PS latest versions. People wont be able to use it on an old 1.7 version. Is that an issue ? |
From my understanding, that would be an improvement available from PS 1.7.y.x On older versions the module will still work as before, which is fine for me. |
@matks Just to be sure, it will be a new message ? That will not changed the message displayed in the cart ? We can have 2 cases:
|
According to the code (but it would be better to check), for case 1 message is currently:
Do you mean in the modal ? |
So, we can change "The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted." for "The product is no longer available in this quantity." on the product page. And keep "The item %product% in your cart is no longer available in this quantity. You cannot proceed with your order until the quantity is adjusted." in the cart like currently. |
I updated both this PR and the one from the Core:
|
By testing the 2 PRs at the same time, I have the message below |
@marionf It's strange, it's the old message o_O |
That's weird, I deleted all the caches and I'm in private navigation @sarahdib has "The product is no longer available in this quantity." in EN-US and "L'article de votre panier (Mug Today is a good day) n'est plus disponible dans cette quantité. Vous ne pouvez pas continuer votre commande avant d'avoir ajusté la quantité." in FR |
@marionf can you try to upgrade the language ? |
@sarahdib Cant reproduce 😐 I have the new message in both usecases Are you sure it depends on the product being already in the cart ? I think there's another condition, somehow related to how much there is in the cart, how much is available, an also the "out of stock mode" Tested:
|
Found the reason behind this behavior with @marionf : I was testing on a product with combinations, she was testing with a product without combinations |
And there is the same probem with a virtual product |
New PR on the core: PrestaShop/PrestaShop#14214 |
@marionf Can we validate this PR now that PrestaShop/PrestaShop#14214 has been approved ? |
All good @matks |
Thanks @jf-viguier that's one more major bug down the road ! |
I've juste added a test to disable launching of showModal if the add to cart request (event) return an error.
EDIT: to be tested with PrestaShop/PrestaShop#14033