Show why an add to cart was rejected instead of doing nothing - #230
Draft
boo-code wants to merge 1 commit into
Draft
Show why an add to cart was rejected instead of doing nothing#230boo-code wants to merge 1 commit into
boo-code wants to merge 1 commit into
Conversation
Core reports a rejected add to cart - out of stock, minimum quantity, product no longer available - by emitting `handleError` and then stops. This theme listened to it nowhere, so the button appeared to do nothing and the reason only surfaced after the customer reloaded the page. Route the add-to-cart case to `showErrorNextToAddtoCartButton`, the extension point core already exposes and already renders into #product-availability, which templates/catalog/_partials/product-add-to-cart.tpl provides. Hummingbird already honours `handleError`; classic did not. Scoped to eventType 'addProductToCart' on purpose: the other emitters fire on pages with no availability slot, and a catch-all listener would start surfacing messages those pages never showed. Fixes PrestaShop/PrestaShop#16260
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CartControllerreturns{"hasError":true,"errors":["This product ... is no longer available."]}- andthemes/_core/js/cart.jsturns that intoprestashop.emit('handleError', {eventType: 'addProductToCart', resp}). Nothing in this theme listened, so the message was dropped and the reason only surfaced after a reload. Hummingbird already registers such a listener; classic never did. This adds it.prestashop._events.handleErrorhas 0 listeners; after it, the error text from the server is displayed. A product that is in stock still adds normally.Measured on a 9.2.x shop with classic 3.1.2, on
upstream/develop's own build:Only
_dev/js/product.jsis changed; no built asset is in the diff.