/**
* @param Product $product
* @param int $quantity
*
* @throws \Dumplie\SharedKernel\Domain\Exception\InvalidCurrencyException
* @throws \Dumplie\Customer\Domain\Exception\ProductNotAvailableException
*/
public function add(Product $product, int $quantity)
{
if (!$product->isAvailable()) {
throw new ProductNotAvailableException($product);
}
if (!$product->price()->hasCurrency($this->currency)) {
throw new InvalidCurrencyException($this->currency, $product->price()->currency());
}
if (array_key_exists((string) $product->sku(), $this->items)) {
$quantity += $this->items[(string) $product->sku()]->quantity();
}
$this->items[(string) $product->sku()] = new CartItem($product->sku(), $quantity);
}