/**
  * @param int    $productId
  * @param string $slug
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *
  * @return \Illuminate\Contracts\View\View|\Illuminate\Http\Response
  */
 public function viewAction(int $productId, string $slug)
 {
     $product = $this->productRepository->loadAlone($productId);
     if (!$product->id) {
         throw new NotFoundHttpException();
     }
     if ($product->slug !== $slug) {
         return $this->responseFactory->redirectToRoute('product::view', ['id' => $product->id, 'slug' => $product->slug], 301);
     }
     return $this->view->make('customer.product.view', ['product' => $this->view->getProduct($product), 'meta' => $this->view->productMeta($product), 'similar' => $this->view->similarProducts($product)]);
 }
Beispiel #2
0
 /**
  * @param Request $request
  * @param string  $sku
  *
  * @throws NotFoundException
  *
  * @return RedirectResponse
  */
 public function putProductTags(Request $request, string $sku)
 {
     $product = $this->productRepository->loadBySku($sku);
     $tagIds = (array) $request->get('tag-ids');
     $this->tagRepository->syncProductTagIds($product, $tagIds);
     $this->webUi->successMessage("Tags updated for `{$product->sku}`");
     return $this->webUi->redirect('products.show', [$product->sku]);
 }
 /**
  * Should be able to set the price by SKU.
  */
 public function testSetPriceBySku()
 {
     $product = $this->makeMock(Product::class);
     $this->productResource->shouldReceive('where->with->limit->first')->atLeast()->once()->andReturn($product);
     $prices = $this->makeMock(HasMany::class);
     $price = $this->makeMock(Price::class);
     $product->expects($this->atLeastOnce())->method('prices')->willReturn($prices);
     $prices->expects($this->atLeastOnce())->method('firstOrNew')->willReturn($price);
     $units = 5;
     $subunits = 99;
     $price->expects($this->atLeastOnce())->method('setAttribute')->withConsecutive(['units', $units], ['subunits', $subunits], ['currency', 'GBP']);
     $price->expects($this->atLeastOnce())->method('save');
     $this->productRepository->setPriceBySku('foo sku', $units, $subunits);
 }
 /**
  * @param Product $product
  *
  * @return Collection
  */
 public function loadSimilarProducts(Product $product)
 {
     return $this->productRepository->loadSimilar($product);
 }
 /**
  * @param string          $sku
  * @param SetPriceRequest $setPriceRequest
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function setProductPrice(string $sku, SetPriceRequest $setPriceRequest)
 {
     $this->productRepository->setPriceBySku($sku, $setPriceRequest->get('units'), $setPriceRequest->get('subunits'));
     return $this->webUi->redirect('products.show', [$sku]);
 }
 /**
  * @return \Illuminate\Contracts\View\View|\Illuminate\Http\Response
  */
 public function viewAction()
 {
     $products = $this->productRepository->loadInStock();
     return $this->viewFactory->make('customer.product.category', compact('products'));
 }