app/Customize/Controller/ProductBlockController.php line 80

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Customize\Service\ProductFetcher;
  4. use Eccube\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class ProductBlockController extends AbstractController
  8. {
  9.     /** @var ProductFetcher */
  10.     private $fetcher;
  11.     public function __construct(ProductFetcher $fetcher)
  12.     {
  13.         $this->fetcher $fetcher;
  14.     }
  15.     /**
  16.      * タグでおすすめ商品ブロック(既存)
  17.      *
  18.      * 例: /block/recommend/tag/2
  19.      *
  20.      * @Route("/block/recommend/tag/{id}", name="block_recommend_tag")
  21.      */
  22.     public function recommendByTag(int $id): Response
  23.     {
  24.         $products $this->fetcher->findByTagId($id8);
  25.         return $this->render('Block/recommend_item.twig', [
  26.             'products' => $products,
  27.         ]);
  28.     }
  29.     /**
  30.      * カテゴリでおすすめ商品ブロック(既存)
  31.      *
  32.      * 例: /block/recommend/category/7
  33.      *
  34.      * @Route("/block/recommend/category/{id}", name="block_recommend_category")
  35.      */
  36.     public function recommendByCategory(int $id): Response
  37.     {
  38.         $products $this->fetcher->findByCategoryId($id8);
  39.         return $this->render('Block/recommend_item.twig', [
  40.             'products' => $products,
  41.         ]);
  42.     }
  43.     /**
  44.      * ★トップ用 おすすめ商品スライダー(タグID=2を最大10件)
  45.      *
  46.      * 例: /block/top_recommend
  47.      *
  48.      * 管理画面 or テンプレートから {{ render(path('block_top_recommend')) }} で呼び出す
  49.      *
  50.      * @Route("/block/top_recommend", name="block_top_recommend")
  51.      */
  52.     public function topRecommend(): Response
  53.     {
  54.         // タグID=2 から最大10件
  55.         $products $this->fetcher->findByTagId(210);
  56.         return $this->render('Block/top_recommend.twig', [
  57.             'products' => $products,
  58.         ]);
  59.     }
  60.     /**
  61.      * 新着商品スライダー(最新10件)
  62.      *
  63.      * 例: /block/new_products
  64.      *
  65.      * {{ render(path('block_new_products')) }} で呼び出し
  66.      *
  67.      * @Route("/block/new_products", name="block_new_products")
  68.      */
  69.     public function newProducts(): Response
  70.     {
  71.         // 最新の商品を10件取得
  72.         $products $this->fetcher->findNewest(10);
  73.         return $this->render('Block/new_products.twig', [
  74.             'products' => $products,
  75.         ]);
  76.     }
  77. }