<?php
namespace Customize\Controller;
use Customize\Service\ProductFetcher;
use Eccube\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ProductBlockController extends AbstractController
{
/** @var ProductFetcher */
private $fetcher;
public function __construct(ProductFetcher $fetcher)
{
$this->fetcher = $fetcher;
}
/**
* タグでおすすめ商品ブロック(既存)
*
* 例: /block/recommend/tag/2
*
* @Route("/block/recommend/tag/{id}", name="block_recommend_tag")
*/
public function recommendByTag(int $id): Response
{
$products = $this->fetcher->findByTagId($id, 8);
return $this->render('Block/recommend_item.twig', [
'products' => $products,
]);
}
/**
* カテゴリでおすすめ商品ブロック(既存)
*
* 例: /block/recommend/category/7
*
* @Route("/block/recommend/category/{id}", name="block_recommend_category")
*/
public function recommendByCategory(int $id): Response
{
$products = $this->fetcher->findByCategoryId($id, 8);
return $this->render('Block/recommend_item.twig', [
'products' => $products,
]);
}
/**
* ★トップ用 おすすめ商品スライダー(タグID=2を最大10件)
*
* 例: /block/top_recommend
*
* 管理画面 or テンプレートから {{ render(path('block_top_recommend')) }} で呼び出す
*
* @Route("/block/top_recommend", name="block_top_recommend")
*/
public function topRecommend(): Response
{
// タグID=2 から最大10件
$products = $this->fetcher->findByTagId(2, 10);
return $this->render('Block/top_recommend.twig', [
'products' => $products,
]);
}
/**
* 新着商品スライダー(最新10件)
*
* 例: /block/new_products
*
* {{ render(path('block_new_products')) }} で呼び出し
*
* @Route("/block/new_products", name="block_new_products")
*/
public function newProducts(): Response
{
// 最新の商品を10件取得
$products = $this->fetcher->findNewest(10);
return $this->render('Block/new_products.twig', [
'products' => $products,
]);
}
}