<?php
namespace Customize\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Page;
use Eccube\Entity\Layout;
use Eccube\Entity\Product;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Form\Type\AddCartType;
use Twig\Environment;
class MyProductPageController extends AbstractController
{
/**
* @Route("/healthfood/millionpower-hg", name="healthfood_millionpower_hg")
* @Route("/healthfood/psyche-hg", name="healthfood_psyche_hg")
* @Route("/healthfood/psyche", name="healthfood_psyche")
* @Route("/healthfood/aozakana", name="healthfood_aozakana")
* @Route("/healthfood/collagen", name="healthfood_collagen")
* @Route("/healthfood/millionpower-sg", name="healthfood_millionpower_sg")
* @Route("/goods/pillow", name="goods_pillow")
* @Route("/vegetable-juice", name="vegetable_juice")
* @Route("/healthfood/onionsoup", name="healthfood_onionsoup")
* @Route("/goods/disinfection-spray", name="goods_disinfection_spray")
* @Route("/healthfood/millionpower", name="healthfood_millionpower")
* @Route("/goods/neteruma-ni", name="goods_neteruma_ni")
* @Route("/juice/blueberry", name="juice_blueberry")
* @Route("/healthfood/5252milk", name="healthfood_5252milk")
* @Route("/healthfood/kyushu-aojiru", name="healthfood_kyushu_aojiru")
* @Route("/healthfood/shikisima-ginger", name="healthfood_shikisima_ginger")
* @Route("/goods/hot-bubble", name="goods_hot_bubble")
* @Route("/goods/massage-roller", name="goods_massage_roller")
* @Route("/goods/eyebrow-stamp", name="goods_eyebrow_stamp")
* @Route("/healthfood/ikameshi", name="healthfood_ikameshi")
* @Route("/healthfood/5252milk-enquete", name="healthfood_5252milk_enquete")
* @Route("/goods/tsuru-m", name="goods_tsuru_m")
* @Route("/healthfood/tsukudani", name="healthfood_tsukudani")
* @Route("/goods/perfect-lifty", name="goods_perfect_lifty")
* @Route("/goods/lifty-lifty", name="goods_lifty_lifty")
* @Route("/goods/eye-lifty", name="goods_eye_lifty")
* @Route("/goods/perfect-whity", name="goods_perfect_whity")
* @Route("/goods/locomo-cream", name="goods_locomo_cream")
* @Route("/goods/locomo-cream-2set", name="goods_locomo_cream_2set")
*/
public function index(Request $request)
{
// ファイル名 => 商品ID
$ProductIDs = array(
'healthfood_millionpower_hg' => 4,
'healthfood_psyche_hg' => 5,
'healthfood_psyche' => 6,
'healthfood_aozakana' => 7,
'healthfood_collagen' => 8,
'healthfood_millionpower_sg' => 9,
'goods_pillow' => 11,
'vegetable_juice' => 12,
'healthfood_onionsoup' => 15,
'goods_disinfection_spray' => 16,
'healthfood_millionpower' => 20,
'goods_neteruma_ni' => 21,
'juice_blueberry' => 22,
'healthfood_5252milk' => 25,
'healthfood_kyushu_aojiru' => 27,
'healthfood_shikisima_ginger' => 29,
'goods_hot_bubble' => 32,
'goods_massage_roller' => 34,
'goods_eyebrow_stamp' => 38,
'healthfood_ikameshi' => 56,
'healthfood_5252milk_enquete' => 57,
'goods_tsuru_m' => 58,
'healthfood_tsukudani' => 59,
'goods_lifty_lifty' => 57,
'goods_eye_lifty' => 61,
'goods_perfect_lifty' => 58,
'goods_perfect_whity' => 60,
'goods_locomo_cream' => 63,
'goods_locomo_cream_2set' => 62,
);
$name = $request->attributes->get('_route');
$file = sprintf('@user_data/%s.twig', $name);
$Layout = $this->entityManager->getRepository('Eccube\Entity\Layout')->get(Layout::DEFAULT_LAYOUT_UNDERLAYER_PAGE);
$Product = $this->entityManager->getRepository('Eccube\Entity\Product')->find($ProductIDs[$name]);
$builder = $this->formFactory->createNamedBuilder(
'',
AddCartType::class,
null,
[
'product' => $Product,
'id_add_product_id' => false,
]
);
$event = new EventArgs(
[
'builder' => $builder,
'Product' => $Product,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE);
$is_favorite = false;
if ($this->isGranted('ROLE_USER')) {
$Customer = $this->getUser();
$is_favorite = $this->entityManager->getRepository('Eccube\Entity\CustomerFavoriteProduct')->isFavorite($Customer, $Product);
}
return $this->render($file, [
'Layout' => $Layout,
'title' => $Product->getName(),
'subtitle' => $Product->getName(),
'form' => $builder->getForm()->createView(),
'Product' => $Product,
'is_favorite' => $is_favorite,
]);
}
}