Пример #1
0
 public function __construct(Product $product, Order $order, Quantity $quantity)
 {
     $this->product = $product;
     $this->order = $order;
     $this->quantity = $quantity;
     $this->price = $product->getPrice();
 }
Пример #2
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;
 }
Пример #3
0
 public function createProduct(CreateProductCommand $command)
 {
     $uuid = Uuid::uuid4();
     $command->setId($uuid);
     $category = $this->categoryRepository->findByIdentity(new UuidIdentity($command->getCategory()));
     $product = new Product(new UuidIdentity($command->getId()), $command->getName(), new Money($command->getPrice()), $category, $command->getDescription(), $command->isAvailable(), $command->getImageUrl());
     foreach ($command->getProductOptions() as $productOption) {
         $option = $this->optionRepository->getReference(new UuidIdentity($productOption->getOption()));
         $product->addOption($option, $productOption->getValue());
     }
     $this->repository->save($product);
     $event = new ProductSavedEvent($product);
     $this->eventBus->handle($event);
 }
Пример #4
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;
 }
Пример #5
0
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $generator = $this->container->get('faker.generator');
     /** @var \FilesystemIterator $iterator */
     $dir = $this->container->getParameter('kernel.root_dir') . '/../web/images/';
     $iterator = new \InfiniteIterator(new \FilesystemIterator($dir, \FilesystemIterator::SKIP_DOTS));
     for ($i = 0; $i < 200; $i++) {
         /** @var Category $category */
         $category = $this->getReference('category_' . mt_rand(1, LoadCategoryData::COUNT));
         $product = new Product(new UuidIdentity(Uuid::uuid4()), $generator->company . ' ' . $generator->words(2, true), new Money($generator->randomNumber(4)), $category, $generator->text(500), $generator->boolean(90), '/images/' . $iterator->getFilename());
         $iterator->next();
         $opts = array_rand(range(1, LoadOptionData::COUNT), mt_rand(2, 5));
         foreach ($opts as $opt) {
             /** @var Option $option */
             $option = $this->getReference('option_' . ($opt + 1));
             $product->addOption($option, $generator->words(2, true));
         }
         $manager->persist($product);
     }
     $manager->flush();
 }
Пример #6
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());
 }