app/Customize/Controller/MyProductPageController.php line 94

Open in your IDE?
  1. <?php
  2. namespace Customize\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Eccube\Controller\AbstractController;
  6. use Eccube\Entity\Page;
  7. use Eccube\Entity\Layout;
  8. use Eccube\Entity\Product;
  9. use Eccube\Event\EccubeEvents;
  10. use Eccube\Event\EventArgs;
  11. use Eccube\Form\Type\AddCartType;
  12. use Twig\Environment;
  13. class MyProductPageController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/healthfood/millionpower-hg", name="healthfood_millionpower_hg")
  17.      * @Route("/healthfood/psyche-hg", name="healthfood_psyche_hg")
  18.      * @Route("/healthfood/psyche", name="healthfood_psyche")
  19.      * @Route("/healthfood/aozakana", name="healthfood_aozakana")
  20.      * @Route("/healthfood/collagen", name="healthfood_collagen")
  21.      * @Route("/healthfood/millionpower-sg", name="healthfood_millionpower_sg")
  22.      * @Route("/goods/pillow", name="goods_pillow")
  23.      * @Route("/vegetable-juice", name="vegetable_juice")
  24.      * @Route("/healthfood/onionsoup", name="healthfood_onionsoup")
  25.      * @Route("/goods/disinfection-spray", name="goods_disinfection_spray")
  26.      * @Route("/healthfood/millionpower", name="healthfood_millionpower")
  27.      * @Route("/goods/neteruma-ni", name="goods_neteruma_ni")
  28.      * @Route("/juice/blueberry", name="juice_blueberry")
  29.      * @Route("/healthfood/5252milk", name="healthfood_5252milk")
  30.      * @Route("/healthfood/kyushu-aojiru", name="healthfood_kyushu_aojiru")
  31.      * @Route("/healthfood/shikisima-ginger", name="healthfood_shikisima_ginger")
  32.      * @Route("/goods/hot-bubble", name="goods_hot_bubble")
  33.      * @Route("/goods/massage-roller", name="goods_massage_roller")
  34.      * @Route("/goods/eyebrow-stamp", name="goods_eyebrow_stamp")
  35.      * @Route("/healthfood/ikameshi", name="healthfood_ikameshi")
  36.      * @Route("/healthfood/5252milk-enquete", name="healthfood_5252milk_enquete")
  37.      * @Route("/goods/tsuru-m", name="goods_tsuru_m")
  38.      * @Route("/healthfood/tsukudani", name="healthfood_tsukudani")
  39.      * @Route("/goods/perfect-lifty", name="goods_perfect_lifty")
  40.      * @Route("/goods/lifty-lifty", name="goods_lifty_lifty")
  41.      * @Route("/goods/eye-lifty", name="goods_eye_lifty")
  42.      * @Route("/goods/perfect-whity", name="goods_perfect_whity")
  43.      * @Route("/goods/locomo-cream", name="goods_locomo_cream")
  44.      * @Route("/goods/locomo-cream-2set", name="goods_locomo_cream_2set")
  45.     */
  46.     public function index(Request $request)
  47.     {
  48.         // ファイル名 => 商品ID
  49.         $ProductIDs = array(
  50.             'healthfood_millionpower_hg' => 4,
  51.             'healthfood_psyche_hg' => 5,
  52.             'healthfood_psyche' => 6,
  53.             'healthfood_aozakana' => 7,
  54.             'healthfood_collagen' => 8,
  55.             'healthfood_millionpower_sg' => 9,
  56.             'goods_pillow' => 11,
  57.             'vegetable_juice' => 12,
  58.             'healthfood_onionsoup' => 15,
  59.             'goods_disinfection_spray' => 16,
  60.             'healthfood_millionpower' => 20,
  61.             'goods_neteruma_ni' => 21,
  62.             'juice_blueberry' => 22,
  63.             'healthfood_5252milk' => 25,
  64.             'healthfood_kyushu_aojiru' => 27,
  65.             'healthfood_shikisima_ginger' => 29,
  66.             'goods_hot_bubble' => 32,
  67.             'goods_massage_roller' => 34,
  68.             'goods_eyebrow_stamp' => 38,
  69.             'healthfood_ikameshi' => 56,
  70.             'healthfood_5252milk_enquete' => 57,
  71.             'goods_tsuru_m' => 58,
  72.             'healthfood_tsukudani' => 59,
  73.             'goods_lifty_lifty' => 57,
  74.             'goods_eye_lifty' => 61,
  75.             'goods_perfect_lifty' => 58,
  76.             'goods_perfect_whity' => 60,
  77.             'goods_locomo_cream' => 63,
  78.             'goods_locomo_cream_2set' => 62,
  79.         );
  80.         $name $request->attributes->get('_route');
  81.         $file sprintf('@user_data/%s.twig'$name);
  82.         $Layout $this->entityManager->getRepository('Eccube\Entity\Layout')->get(Layout::DEFAULT_LAYOUT_UNDERLAYER_PAGE);
  83.         $Product $this->entityManager->getRepository('Eccube\Entity\Product')->find($ProductIDs[$name]);
  84.         $builder $this->formFactory->createNamedBuilder(
  85.             '',
  86.             AddCartType::class,
  87.             null,
  88.             [
  89.                 'product' => $Product,
  90.                 'id_add_product_id' => false,
  91.             ]
  92.         );
  93.         $event = new EventArgs(
  94.             [
  95.                 'builder' => $builder,
  96.                 'Product' => $Product,
  97.             ],
  98.             $request
  99.         );
  100.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE);
  101.         $is_favorite false;
  102.         if ($this->isGranted('ROLE_USER')) {
  103.             $Customer $this->getUser();
  104.             $is_favorite $this->entityManager->getRepository('Eccube\Entity\CustomerFavoriteProduct')->isFavorite($Customer$Product);
  105.         }
  106.         return $this->render($file, [
  107.             'Layout' => $Layout,
  108.             'title' => $Product->getName(),
  109.             'subtitle' => $Product->getName(),
  110.             'form' => $builder->getForm()->createView(),
  111.             'Product' => $Product,
  112.             'is_favorite' => $is_favorite,
  113.         ]);
  114.     }
  115. }