示例#1
0
 /**
  * {@inheritdoc}
  */
 public function getCart()
 {
     if (null !== $this->cart) {
         return $this->cart;
     }
     $cartIdentifier = $this->storage->getCurrentCartIdentifier();
     if ($cartIdentifier && ($cart = $this->getCartByIdentifier($cartIdentifier))) {
         return $this->cart = $cart;
     }
     $cart = $this->repository->createNew();
     $this->manager->persist($cart);
     $this->manager->flush($cart);
     $this->setCart($cart);
     return $cart;
 }
 /**
  * {@inheritdoc}
  */
 public function create(StockableInterface $stockable, $quantity = 1, $state = InventoryUnitInterface::STATE_SOLD)
 {
     if ($quantity < 1) {
         throw new \InvalidArgumentException('Quantity of units must be greater than 1');
     }
     $units = new ArrayCollection();
     for ($i = 0; $i < $quantity; $i++) {
         $inventoryUnit = $this->repository->createNew();
         $inventoryUnit->setStockable($stockable);
         $inventoryUnit->setInventoryState($state);
         $units->add($inventoryUnit);
     }
     return $units;
 }