public function testHandle()
 {
     $pricing = $this->dummyData->getPricing();
     $dtoBuilderFactory = $this->getDTOBuilderFactory();
     $productService = $this->mockService->getProductService();
     $productService->shouldReceive('getRandomProducts')->andReturn([$this->dummyData->getProduct()])->once();
     $limit = 4;
     $request = new GetRandomProductsRequest($limit);
     $response = new GetRandomProductsResponse($pricing);
     $handler = new GetRandomProductsHandler($productService, $dtoBuilderFactory);
     $handler->handle(new GetRandomProductsQuery($request, $response));
     $this->assertTrue($response->getProductDTOs()[0] instanceof ProductDTO);
 }
 /**
  * @param string $slug
  * @param string $productId
  * @return \Illuminate\Http\RedirectResponse
  */
 public function show($slug, $productId)
 {
     $request = new GetProductRequest($productId);
     $response = new GetProductResponse($this->getPricing());
     $this->dispatchQuery(new GetProductQuery($request, $response));
     $productDTO = $response->getProductDTOWithAllData();
     if ($slug !== $productDTO->slug) {
         return redirect()->route('product.show', ['slug' => $productDTO->slug, 'productId' => $productDTO->id->getHex()]);
     }
     $request = new GetRandomProductsRequest(4);
     $response = new GetRandomProductsResponse($this->getPricing());
     $this->dispatchQuery(new GetRandomProductsQuery($request, $response));
     $relatedProductDTOs = $response->getProductDTOs();
     return $this->renderTemplate('product/show.twig', ['product' => $productDTO, 'relatedProducts' => $relatedProductDTOs]);
 }
Exemplo n.º 3
0
 protected function getRandomProducts($limit)
 {
     $request = new GetRandomProductsRequest($limit);
     $response = new GetRandomProductsResponse($this->getPricing());
     $this->dispatchQuery(new GetRandomProductsQuery($request, $response));
     return $response->getProductDTOs();
 }
 /**
  * @param OrderDTO $order
  * @return ProductDTO[]
  */
 private function getRecommendedProductsFromOrder(OrderDTO $order)
 {
     $productIds = [];
     foreach ($order->orderItems as $orderItem) {
         $productIds[] = $orderItem->product->id->getHex();
     }
     $request = new GetRandomProductsRequest(4);
     $response = new GetRandomProductsResponse($this->getPricing());
     $this->dispatchQuery(new GetRandomProductsQuery($request, $response));
     // TODO: Switch to related products
     //        $request = new GetRelatedProductsRequest($productIds, 4);
     //        $response = new GetRelatedProductsResponse($this->getPricing());
     //        $this->dispatchQuery(new GetRelatedProductsQuery($request, $response));
     return $response->getProductDTOs();
 }