/** * {@inheritDoc} */ public function apply(CartInterface $cart, $transition, $andFlush = false) { $finiteStateMachine = $this->finiteContext->getStateMachine($cart); if ($finiteStateMachine->can($transition)) { $finiteStateMachine->apply($transition); if ($andFlush) { $this->cartManager->updateCart($cart); } return true; } throw new TransitionException($transition, $cart->getState()); }
/** * @param CartInterface $cart * @param ItemInterface $item * @param array $parameters * * @return CartInterface * @throws \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException */ public function patchItem(CartInterface $cart, ItemInterface $item, array $parameters) { $this->applyWriteTransition($cart); $productFamily = $this->productFamilyProvider->getProductFamily($parameters); if (null == $productFamily) { throw new NotAcceptableHttpException('Impossible to fetch product Family from Request.'); } $cartItemHandler = $this->strategy->getItemHandler($productFamily); $item = $cartItemHandler->patchItem($cart, $item, $parameters); $event = $this->eventFactory->getEvent($cart, $item, $parameters); $this->dispatcher->dispatch(LeaphlyCartEvents::ITEM_CREATE_SUCCESS, $event); $item = $event->getItem(); $cart = $event->getCart(); $this->cartManager->updateCart($cart); $this->dispatcher->dispatch(LeaphlyCartEvents::ITEM_CREATE_COMPLETED, $this->eventFactory->getEvent($cart, $item)); return $cart; }