Ejemplo n.º 1
0
 public function addItem(OrderInterface $order, ItemInterface $item)
 {
     if (!$this->hasCartInSession($order->getId())) {
         throw new OrderAccessForbiddenException(Translate::t("The requested cart does not belong to you."));
     }
     if ($order->getStatus() !== $order::STATUS_OPEN) {
         throw new OrderModificationException(Translate::t("This item cannot be added because the order is no longer open."));
     }
     return $this->orderService->addItem($order, $item);
 }
Ejemplo n.º 2
0
 public function addItem(OrderInterface $order, ItemInterface $item)
 {
     if ($this->entityManager->contains($item)) {
         throw new InternalErrorException("You may only add unmanaged item entities to the order.");
     }
     try {
         $this->entityManager->beginTransaction();
         $order->addItem($item);
         if ($order->getStatus() === OrderInterface::STATUS_OPEN) {
             $order->setCreated(new DateTime());
         }
         $item->setOrder($order);
         $item->setStatus($item::STATUS_RESERVED);
         $this->validate($order);
         $this->entityManager->persist($order);
         $this->entityManager->flush();
         $this->eventDispatcher->dispatch("agit.item.created", new ItemEvent($item));
         $this->entityManager->commit();
     } catch (Exception $e) {
         $this->entityManager->rollback();
         throw $e;
     }
 }