mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
Add post-event dispatches for cart operations
This commit is contained in:
parent
0a6bb24f47
commit
8c492dbf4d
4 changed files with 14 additions and 0 deletions
|
|
@ -90,6 +90,7 @@ class OrderController extends ResourceController
|
|||
|
||||
$this->getEventDispatcher()->dispatch(new GenericEvent($resource), SyliusCartEvents::CART_CHANGE);
|
||||
$this->manager->flush();
|
||||
$this->getEventDispatcher()->dispatch(new GenericEvent($resource), SyliusCartEvents::CART_POST_CHANGE);
|
||||
|
||||
if (!$configuration->isHtmlRequest()) {
|
||||
return $this->createRestView($configuration, null, Response::HTTP_NO_CONTENT);
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ class FormComponent
|
|||
if ($form->isValid()) {
|
||||
$this->eventDispatcher->dispatch(new GenericEvent($form->getData()), SyliusCartEvents::CART_CHANGE);
|
||||
$this->manager->flush();
|
||||
$this->eventDispatcher->dispatch(new GenericEvent($form->getData()), SyliusCartEvents::CART_POST_CHANGE);
|
||||
$this->emit(self::SYLIUS_SHOP_CART_CHANGED, ['cartId' => $this->resource->getId()]);
|
||||
}
|
||||
}
|
||||
|
|
@ -106,6 +107,7 @@ class FormComponent
|
|||
$this->manager->persist($this->resource);
|
||||
$this->manager->flush();
|
||||
$this->manager->refresh($this->resource);
|
||||
$this->eventDispatcher->dispatch(new GenericEvent($orderItem), SyliusCartEvents::CART_ITEM_POST_REMOVE);
|
||||
|
||||
$this->shouldSaveCart = false;
|
||||
$this->submitForm();
|
||||
|
|
@ -121,8 +123,10 @@ class FormComponent
|
|||
|
||||
$this->formValues['items'] = [];
|
||||
$this->eventDispatcher->dispatch(new GenericEvent($this->resource), SyliusCartEvents::CART_CLEAR);
|
||||
$clearedCart = $this->resource;
|
||||
$this->manager->remove($this->resource);
|
||||
$this->manager->flush();
|
||||
$this->eventDispatcher->dispatch(new GenericEvent($clearedCart), SyliusCartEvents::CART_POST_CLEAR);
|
||||
|
||||
$this->resource = $this->createResource();
|
||||
$this->resetForm();
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ class AddToCartFormComponent
|
|||
$this->eventDispatcher->dispatch(new GenericEvent($addToCartCommand), SyliusCartEvents::CART_ITEM_ADD);
|
||||
$this->manager->persist($addToCartCommand->getCart());
|
||||
$this->manager->flush();
|
||||
$this->eventDispatcher->dispatch(new GenericEvent($addToCartCommand), SyliusCartEvents::CART_ITEM_POST_ADD);
|
||||
|
||||
if ($addFlashMessage) {
|
||||
FlashBagProvider::getFlashBag($this->requestStack)->add('success', 'sylius.cart.add_item');
|
||||
|
|
|
|||
|
|
@ -17,11 +17,19 @@ interface SyliusCartEvents
|
|||
{
|
||||
public const CART_CHANGE = 'sylius.cart_change';
|
||||
|
||||
public const CART_POST_CHANGE = 'sylius.cart_post_change';
|
||||
|
||||
public const CART_CLEAR = 'sylius.cart_clear';
|
||||
|
||||
public const CART_POST_CLEAR = 'sylius.cart_post_clear';
|
||||
|
||||
public const CART_ITEM_ADD = 'sylius.cart_item_add';
|
||||
|
||||
public const CART_ITEM_POST_ADD = 'sylius.cart_item_post_add';
|
||||
|
||||
public const CART_ITEM_REMOVE = 'sylius.cart_item_remove';
|
||||
|
||||
public const CART_ITEM_POST_REMOVE = 'sylius.cart_item_post_remove';
|
||||
|
||||
public const CART_SUMMARY = 'sylius.cart_summary';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue