예제 #1
0
 public function addProduct(AddProductCommand $command)
 {
     $cart = $this->repository->getCart();
     $product = $this->productRepository->findByIdentity(new UuidIdentity($command->getProductId()));
     $cart->addProduct($product, new Quantity($command->getQuantity()));
     $this->repository->setCart($cart);
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public function getCart() : Cart
 {
     $data = $this->session->get(self::NAME, []);
     $lineItems = new ArrayCollection();
     $products = $this->repository->findByIdentities(array_keys($data));
     foreach ($products as $product) {
         $lineItem = new LineItem($product, new Quantity($data[$product->getId()->getValue()]));
         $lineItems->set($product->getId()->getValue(), $lineItem);
     }
     return new Cart($lineItems);
 }
예제 #3
0
 public function updateProduct(UpdateProductCommand $command)
 {
     $product = $this->repository->findByIdentity(new UuidIdentity($command->getId()));
     $category = $this->categoryRepository->findByIdentity(new UuidIdentity($command->getCategory()));
     $product->updateInfo($command->getName(), new Money($command->getPrice()), $category, $command->getDescription(), $command->isAvailable(), $command->getImageUrl());
     $productOptions = $command->getProductOptions();
     foreach ($product->getProductOptions() as $key => $productOption) {
         if (isset($productOptions[$key])) {
             $productOption->changeValue($productOptions[$key]->getValue());
             unset($productOptions[$key]);
         } else {
             $product->getProductOptions()->remove($key);
         }
     }
     foreach ($productOptions 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);
 }