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());
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 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);
     }
 }
Beispiel #4
0
 /**
  * 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);
 }
 function it_sets_currency_on_order($currencyContext, CartEvent $event, OrderInterface $order)
 {
     $event->getCart()->willReturn($order);
     $currencyContext->getCurrency()->shouldBeCalled()->willReturn('PLN');
     $this->processOrderCurrency($event);
 }
Beispiel #6
0
 /**
  * @param CartInterface     $cart
  * @param CartItemInterface $item
  */
 public function __construct(CartInterface $cart, CartItemInterface $item)
 {
     parent::__construct($cart);
     $this->item = $item;
 }