コード例 #1
0
ファイル: ProductService.php プロジェクト: igaponov/shop
 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);
 }