Exemplo n.º 1
0
 /**
  * @param CartInterface $cart
  * @param CartItemInterface $item
  */
 private function resolveCartItem(CartInterface $cart, CartItemInterface $item)
 {
     foreach ($cart->getItems() as $existingItem) {
         if ($item->equals($existingItem)) {
             $this->orderItemQuantityModifier->modify($existingItem, $existingItem->getQuantity() + $item->getQuantity());
             return;
         }
     }
     $cart->addItem($item);
 }
Exemplo n.º 2
0
 public function setCart(CartInterface $cart)
 {
     $user = $this->getUser();
     if ($cart !== $this->getCart()) {
         $this->abandonCart();
     }
     if ($cart instanceof OrderInterface && $user instanceof UserInterface) {
         $cart->setUser($user);
         $cart->setExpiresAt(null);
     }
 }
Exemplo n.º 3
0
 function it_sets_cart_identifier_via_session($session, CartInterface $cart)
 {
     $cart->getIdentifier()->will(function () {
         return 3;
     });
     $session->set(SessionCartStorage::KEY, 3)->will(function () use($session) {
         $session->get(SessionCartStorage::KEY)->willReturn(3);
     });
     $this->setCurrentCartIdentifier($cart);
     $this->getCurrentCartIdentifier()->shouldReturn(3);
 }
Exemplo n.º 4
0
 function it_throw_exception_if_subject_is_not_a_cart(GenericEvent $event, CartInterface $cart)
 {
     $event->getSubject()->shouldBeCalled()->willReturn(null);
     $cart->calculateTotal()->shouldNotBeCalled();
     $this->shouldThrow('\\InvalidArgumentException')->during('refreshCart', array($event));
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function setCurrentCartIdentifier(CartInterface $cart)
 {
     $this->session->set($this->key, $cart->getIdentifier());
 }
Exemplo n.º 6
0
 function it_removes_cart_item_from_cart(OrderProcessorInterface $orderProcessor, CartInterface $cart, CartItemInterface $cartItem)
 {
     $cart->removeItem($cartItem)->shouldBeCalled();
     $orderProcessor->process($cart)->shouldBeCalled();
     $this->removeFromCart($cart, $cartItem);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function setCurrentCartIdentifier(CartInterface $cart)
 {
     $this->storage->setData(self::STORAGE_KEY, $cart->getIdentifier());
 }