Skip to content

Show why an add to cart was rejected instead of doing nothing - #230

Draft
boo-code wants to merge 1 commit into
PrestaShop:developfrom
boo-code:fix/show-add-to-cart-errors-16260
Draft

Show why an add to cart was rejected instead of doing nothing#230
boo-code wants to merge 1 commit into
PrestaShop:developfrom
boo-code:fix/show-add-to-cart-errors-16260

Conversation

@boo-code

@boo-code boo-code commented Sep 3, 2026

Copy link
Copy Markdown
Contributor
Questions Answers
Description? Adding a product to the cart from the product page when it has just gone out of stock does nothing visible: no modal, no message. The server answers correctly - CartController returns {"hasError":true,"errors":["This product ... is no longer available."]} - and themes/_core/js/cart.js turns that into prestashop.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.
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? PrestaShop/PrestaShop#16260
Sponsor company -
How to test? Set a product to out of stock with "Deny orders" and open its product page in this theme, then click "Add to cart". Before this change nothing happens and prestashop._events.handleError has 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:

prestashop._events.handleError                    -> 0 listeners
click "Add to cart" on a now-out-of-stock product
  events emitted                                  -> ["handleError"]
  #product-availability                           -> unchanged
  .alert-danger                                   -> none
  page text contains "no longer available"        -> false

Only _dev/js/product.js is changed; no built asset is in the diff.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant