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); }