public function createImageForProduct(UploadFileDTO $uploadFileDTO, UuidInterface $productId) { $managedFile = $this->fileManager->saveFile($uploadFileDTO->getFilePath()); $image = new Image(); $image->setPath($managedFile->getUri()); $image->setWidth($managedFile->getWidth()); $image->setHeight($managedFile->getHeight()); $product = $this->productRepository->findOneById($productId); $product->addImage($image); $this->create($image); }
/** * @param UuidInterface $productId * @param UuidInterface $imageId * @throws EntityNotFoundException */ public function removeImage(UuidInterface $productId, UuidInterface $imageId) { $product = $this->productRepository->findOneById($productId); $image = $this->imageRepository->findOneById($imageId); $product->removeImage($image); $this->productRepository->update($product); if ($image->getTag() === null) { $this->imageRepository->delete($image); } }
/** * @param UuidInterface $cartItemId * @param UuidInterface $cartId * @param UuidInterface $productId * @param int $quantity * @return CartItem */ public function addItem(UuidInterface $cartItemId, UuidInterface $cartId, UuidInterface $productId, $quantity = 1) { $product = $this->productRepository->findOneById($productId); $cart = $this->cartRepository->findOneById($cartId); $cart->setShipmentRate(null); $cartItem = new CartItem($cartItemId); $cartItem->setProduct($product); $cartItem->setQuantity($quantity); $cart->addCartItem($cartItem); $this->cartRepository->update($cart); return $cartItem; }
public function findOneById(UuidInterface $id) { return $this->productRepository->findOneById($id); }