app/Customize/Controller/ProductBlockController.php line 81

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