/** * @param Product $product * @param Quantity $quantity * @return Order */ public function addProduct(Product $product, Quantity $quantity) : Order { if (!$product->isAvailable()) { throw new \RuntimeException(sprintf('Product #%s is not available', $product->getId())); } $lineItem = new LineItem($product, $this, $quantity); $this->lineItems->add($lineItem); return $this; }
/** * @param LineItem $item * * @return $this */ public function addLineItem(LineItem $item) { if (!$this->lineItems->contains($item)) { $item->setShoppingList($this); $this->lineItems->add($item); } return $this; }