public function testCreateImageForProduct() { $uploadFileDTO = $this->dummyData->getUploadFileDTO(); $managedFile = $this->dummyData->getLocalManagedFile(); $this->fileManager->shouldReceive('saveFile')->with($uploadFileDTO->getFilePath())->once()->andReturn($managedFile); $product = $this->dummyData->getProduct(); $this->productRepository->shouldReceive('findOneById')->with($product->getId())->andReturn($product)->once(); $this->imageRepository->shouldReceive('create')->once(); $this->imageService->createImageForProduct($uploadFileDTO, $product->getId()); }
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); }
public function testGetRandomProducts() { $limit = 1; $product1 = $this->dummyData->getProduct(); $this->productRepository->shouldReceive('getRandomProducts')->with($limit)->andReturn([$product1])->once(); $products = $this->productService->getRandomProducts($limit); $this->assertEntitiesEqual($product1, $products[0]); }
public function testAddItem() { $product = $this->dummyData->getProduct(); $this->productRepository->shouldReceive('findOneById')->with($product->getId())->andReturn($product)->once(); $cart = $this->getCartThatRepositoryWillFind(); $this->cartRepositoryShouldUpdateOnce($cart); $cartItemId = Uuid::uuid4(); $cartItem = $this->cartService->addItem($cartItemId, $cart->getId(), $product->getid()); $this->assertEntitiesEqual($cartItem, $cart->getCartItems()[0]); $this->assertSame(null, $cart->getShipmentRate()); }
/** * @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; }
/** * @param int $limit * @return Product[] */ public function getRandomProducts($limit) { return $this->productRepository->getRandomProducts($limit); }
private function loadProductTagsFromOrderItem(OrderItem $orderItem) { $products = [$orderItem->getProduct()]; $this->productRepository->loadProductTags($products); }
public function flush() { return $this->productRepository->flush(); }