Esempio n. 1
0
 function it_should_remove_a_item_to_a_cart_from_event(CartItemEvent $event, CartInterface $cart, CartItemInterface $cartItem)
 {
     $event->getCart()->willReturn($cart);
     $event->getItem()->willReturn($cartItem);
     $cart->removeItem($cartItem)->shouldBeCalled();
     $this->removeItem($event);
 }
Esempio n. 2
0
 /**
  * @param CartItemEvent $event
  */
 public function removeItem(CartItemEvent $event)
 {
     $cart = $event->getCart();
     $cart->removeItem($event->getItem());
 }
Esempio n. 3
0
 /**
  * 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();
 }