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); } }
/** * This action is used to submit the cart summary form. * If the form and updated cart are valid, it refreshes * the cart data and saves it using the operator. * * If there are any errors, it displays the cart summary page. * * @param Request $request * * @return Response */ public function saveAction(Request $request) { $cart = $this->getCurrentCart(); $form = $this->createForm('sylius_cart', $cart); if ($form->handleRequest($request)->isValid()) { $event = new CartEvent($cart); $event->isFresh(true); $eventDispatcher = $this->getEventDispatcher(); $eventDispatcher->dispatch(SyliusCartEvents::CART_CHANGE, new GenericEvent($cart)); // Update models $eventDispatcher->dispatch(SyliusCartEvents::CART_SAVE_INITIALIZE, $event); // Write flash message $eventDispatcher->dispatch(SyliusCartEvents::CART_SAVE_COMPLETED, new FlashEvent()); return $this->redirectToCartSummary(); } $view = $this->view()->setTemplate($this->config->getTemplate('summary.html'))->setData(array('cart' => $cart, 'form' => $form->createView())); return $this->handleView($view); }
/** * 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(); }
/** * @param CartInterface $cart * @param CartItemInterface $item */ public function __construct(CartInterface $cart, CartItemInterface $item) { parent::__construct($cart); $this->item = $item; $this->subject = $item; }
function it_sets_currency_on_order($currencyContext, CartEvent $event, OrderInterface $order) { $event->getCart()->willReturn($order); $currencyContext->getCurrency()->shouldBeCalled()->willReturn('PLN'); $this->processOrderCurrency($event); }