Beispiel #1
0
 /**
  * @param Product $product
  * @param Quantity $quantity
  * @return Cart
  */
 public function addProduct(Product $product, Quantity $quantity) : Cart
 {
     $key = $product->getId()->getValue();
     /** @var LineItem $lineItem */
     $lineItem = $this->lineItems->get($key);
     if ($lineItem === null) {
         $lineItem = new LineItem($product, $quantity);
     } else {
         $lineItem = new LineItem($product, $lineItem->getQuantity()->add($quantity));
     }
     $this->lineItems->set($key, $lineItem);
     return $this;
 }
Beispiel #2
0
 public function testConstruct()
 {
     $uuid = $this->getUuidMock();
     $name = 'test product';
     $price = new Money(10000);
     $category = new Category(new UuidIdentity('uuid2'), 'test cat');
     $description = 'description';
     $availability = true;
     $product = new Product($uuid, $name, $price, $category, $description, $availability, '/');
     $this->assertSame($uuid, $product->getId());
     $this->assertSame($name, $product->getName());
     $this->assertSame($price, $product->getPrice());
     $this->assertSame($category, $product->getCategory());
     $this->assertSame($description, $product->getDescription());
     $this->assertTrue($product->isAvailable());
 }
Beispiel #3
0
 /**
  * @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;
 }