<?php
namespace App\Controller\Product;
use App\Entity\Main\Product\Item;
use App\Entity\Main\Product\Product;
use App\Repository\Main\Product\ItemRepository;
use App\Repository\Main\Product\ProductRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ItemController extends AbstractController
{
/**
* @Route("/urunler/{categorySlug}", name="product_item")
*/
public function index(Request $request, ItemRepository $itemRepository, $categorySlug, ProductRepository $productRepository): Response
{
/** @var Product $product */
$product = $productRepository->findOneBy([
'slug' => $categorySlug,
]);
$request->query->set('locale', $request->getLocale());
$request->query->set('product_id', $product->getId());
$request->query->set('status_id', Item::STATUS['ACTIVE']);
$itemPaginator = $itemRepository->findByRequest($request);
return $this->render('product/item/index.html.twig', [
'itemPaginator' => $itemPaginator,
'product' => $product,
]);
}
/**
* @Route("/urun/{categorySlug}/{itemSlug}", name="product_item_show")
*/
public function show(ItemRepository $itemRepository, $itemSlug): Response
{
$item = $itemRepository->findOneBy([
'slug' => $itemSlug,
]);
return $this->render('product/item/show.html.twig', [
'item' => $item,
]);
}
}