/** * Removes item from cart. * It takes an item id as an argument. * * If the item is found and the current user cart contains that item, * it will be removed and the cart - refreshed and saved. * * @param mixed $id * * @return Response */ public function removeAction($id) { $cart = $this->getCurrentCart(); $item = $this->getRepository()->find($id); $eventDispatcher = $this->getEventDispatcher(); if (!$item || false === $cart->hasItem($item)) { // Write flash message $eventDispatcher->dispatch(SyliusCartEvents::ITEM_REMOVE_ERROR, new FlashEvent()); return $this->redirectToCartSummary(); } $event = new CartItemEvent($cart, $item); $event->isFresh(true); // Update models $eventDispatcher->dispatch(SyliusCartEvents::ITEM_REMOVE_INITIALIZE, $event); $eventDispatcher->dispatch(SyliusCartEvents::CART_CHANGE, new GenericEvent($cart)); $eventDispatcher->dispatch(SyliusCartEvents::CART_SAVE_INITIALIZE, $event); // Write flash message $eventDispatcher->dispatch(SyliusCartEvents::ITEM_REMOVE_COMPLETED, new FlashEvent()); return $this->redirectToCartSummary(); }