don't show the 'added to your cart' message if the item quantity is unchanged or 0; make CartEntityAddEvent aware of the original order item

Created on 15 December 2017, about 7 years ago
Updated 7 November 2023, about 1 year ago

An event subscriber that reacts to CartEvents::CART_ENTITY_ADD can change the quantity of items in the order item, for example to impose a maximum quantity in the order.

Use cases: shipping might have a maximum package size, or licenses allow only 1 of a product to be bought.

This can sometimes result in nothing being added to the cart at all. However, the message that you have added an item to your cart still shows.

To fix this, we need CartEntityAddEvent to be aware of the original order item, if CartManager::addOrderItem() found a matching order item already in the cart.

That requires a new param to its constructor. I can't see anything on https://www.drupal.org/core/d8-bc-policy about whether event classes are considered internal in core, but I think it's safe to say that nobody else should be constructing a CartEntityAddEvent object, and as the class is hardcoded when the event is triggered, it's not something that's meant to be swappable.

🐛 Bug report
Status

Closed: won't fix

Version

2.0

Component

User experience

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024