Document post-flush cart events in upgrade guide

This commit is contained in:
Tomasz Kaliński 2026-06-15 11:19:01 +02:00
parent 8c492dbf4d
commit 860e3a1180

View file

@ -139,6 +139,38 @@
| `ShippingBundle\...\ShippingMethodCalculatorExists` | `invalidShippingCalculator` | `invalidShippingCalculatorMessage` |
| `ShippingBundle\...\ShippingMethodRule` | `invalidType` | `invalidTypeMessage` |
## New Features
1. New post-flush cart events have been added to `Sylius\Component\Order\SyliusCartEvents`.
The following events are now dispatched **after** `$manager->flush()`, allowing listeners to react once the cart has been safely persisted to the database:
| New constant | Event name |
|---|---|
| `SyliusCartEvents::CART_ITEM_POST_ADD` | `sylius.cart_item_post_add` |
| `SyliusCartEvents::CART_ITEM_POST_REMOVE` | `sylius.cart_item_post_remove` |
| `SyliusCartEvents::CART_POST_CHANGE` | `sylius.cart_post_change` |
| `SyliusCartEvents::CART_POST_CLEAR` | `sylius.cart_post_clear` |
Example usage — sending a cart to an external service only after it is stored:
```php
use Sylius\Component\Order\SyliusCartEvents;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\EventDispatcher\GenericEvent;
#[AsEventListener(event: SyliusCartEvents::CART_ITEM_POST_ADD)]
final class SendCartToMarketingAutomationListener
{
public function __invoke(GenericEvent $event): void
{
// Cart is already persisted — safe to send to external service.
}
}
```
The existing pre-flush events (`CART_ITEM_ADD`, `CART_ITEM_REMOVE`, `CART_CHANGE`, `CART_CLEAR`) remain unchanged.
## Deprecations
1. Passing a `Sylius\Component\Core\Calculator\ProductVariantPricesCalculatorInterface` directly to the following catalog-facing classes is deprecated since Sylius 2.3.