function it_sets_customer_on_a_cart($customerContext, CartEvent $event, CustomerAwareInterface $cart, CustomerInterface $customer) { $event->getCart()->willReturn($cart); $customerContext->getCustomer()->willReturn($customer); $cart->setCustomer($customer)->shouldBeCalled(); $this->setCustomer($event); }
public function processOrderCurrency(CartEvent $event) { $order = $event->getCart(); if (!$order instanceof OrderInterface) { throw new UnexpectedTypeException($order, 'Sylius\\Component\\Core\\Model\\OrderInterface'); } $order->setCurrency($this->currencyContext->getCurrency()); }
function it_should_not_save_an_invalid_cart($manager, $provider, $validator, CartEvent $event, CartInterface $cart, ConstraintViolationListInterface $constraintList) { $constraintList->count()->willReturn(1); $event->getCart()->willReturn($cart); $validator->validate($cart)->shouldBeCalled()->willReturn($constraintList); $manager->persist($cart)->shouldNotBeCalled(); $manager->flush()->shouldNotBeCalled(); $provider->setCart($cart)->shouldNotBeCalled(); $this->saveCart($event); }
public function saveCart(CartEvent $event) { $cart = $event->getCart(); $errors = $this->validator->validate($cart); $valid = 0 === count($errors); if ($valid) { $this->cartManager->persist($cart); $this->cartManager->flush(); $this->cartProvider->setCart($cart); } }
/** * Save & persist the subscriptions. * * @param CartEvent $event */ public function onCartSave(CartEvent $event) { $cart = $event->getCart(); foreach ($cart->getItems() as $item) { /** @var OrderItemInterface $item */ if (null === ($subscription = $item->getSubscription())) { continue; } $now = new \DateTime(); $subscription->setVariant($item->getVariant()); $subscription->setQuantity($item->getQuantity()); $subscription->setScheduledDate($now->add($subscription->getInterval())); if (null !== ($user = $this->getUser())) { $subscription->setUser($user); } if (null === $subscription->getId()) { $this->manager->persist($subscription); } } $this->manager->flush(); }
function it_sets_currency_on_order($currencyContext, CartEvent $event, OrderInterface $order) { $event->getCart()->willReturn($order); $currencyContext->getCurrency()->shouldBeCalled()->willReturn('PLN'); $this->processOrderCurrency($event); }