app/Customize/Controller/ProductController.php line 242

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Controller;
  13. use Eccube\Entity\BaseInfo;
  14. use Eccube\Entity\Master\ProductStatus;
  15. use Eccube\Entity\Product;
  16. use Eccube\Entity\ProductClass;
  17. use Eccube\Event\EccubeEvents;
  18. use Eccube\Event\EventArgs;
  19. use Customize\Form\Type\AddCartType;
  20. use Customize\Form\Type\SearchProductType;
  21. use Eccube\Repository\BaseInfoRepository;
  22. use Eccube\Repository\CustomerFavoriteProductRepository;
  23. use Eccube\Repository\Master\ProductListMaxRepository;
  24. use Customize\Repository\ProductRepository;
  25. use Eccube\Controller\AbstractController;
  26. use Eccube\Service\CartService;
  27. use Eccube\Service\PurchaseFlow\PurchaseContext;
  28. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  29. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  30. use Knp\Component\Pager\PaginatorInterface;
  31. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  32. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  33. use Symfony\Component\HttpFoundation\Request;
  34. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  35. use Symfony\Component\Routing\Annotation\Route;
  36. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  37. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  38. use Plugin\ProductField\Repository\ConfigRepository;
  39. class ProductController extends AbstractController
  40. {
  41.     /**
  42.      * @var PurchaseFlow
  43.      */
  44.     protected $purchaseFlow;
  45.     /**
  46.      * @var CustomerFavoriteProductRepository
  47.      */
  48.     protected $customerFavoriteProductRepository;
  49.     /**
  50.      * @var CartService
  51.      */
  52.     protected $cartService;
  53.     /**
  54.      * @var ProductRepository
  55.      */
  56.     protected $productRepository;
  57.     /**
  58.      * @var BaseInfo
  59.      */
  60.     protected $BaseInfo;
  61.     /**
  62.      * @var AuthenticationUtils
  63.      */
  64.     protected $helper;
  65.     /**
  66.      * @var ProductListMaxRepository
  67.      */
  68.     protected $productListMaxRepository;
  69.     private $title '';
  70.     /**
  71.      * ProductController constructor.
  72.      *
  73.      * @param PurchaseFlow $cartPurchaseFlow
  74.      * @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
  75.      * @param CartService $cartService
  76.      * @param ProductRepository $productRepository
  77.      * @param BaseInfoRepository $baseInfoRepository
  78.      * @param AuthenticationUtils $helper
  79.      * @param ProductListMaxRepository $productListMaxRepository
  80.      */
  81.     public function __construct(
  82.         PurchaseFlow $cartPurchaseFlow,
  83.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  84.         CartService $cartService,
  85.         ProductRepository $productRepository,
  86.         BaseInfoRepository $baseInfoRepository,
  87.         AuthenticationUtils $helper,
  88.         ProductListMaxRepository $productListMaxRepository,
  89.         ConfigRepository $ConfigRepository
  90.     ) {
  91.         $this->purchaseFlow $cartPurchaseFlow;
  92.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  93.         $this->cartService $cartService;
  94.         $this->productRepository $productRepository;
  95.         $this->BaseInfo $baseInfoRepository->get();
  96.         $this->helper $helper;
  97.         $this->productListMaxRepository $productListMaxRepository;
  98.         $this->ConfigRepository $ConfigRepository;
  99.     }
  100.     /**
  101.      * 商品一覧画面.
  102.      *
  103.      * @Route("/products/list", name="product_list", methods={"GET"})
  104.      * @Template("Product/list.twig")
  105.      */
  106.     public function index(Request $requestPaginatorInterface $paginator)
  107.     {
  108.         // Doctrine SQLFilter
  109.         if ($this->BaseInfo->isOptionNostockHidden()) {
  110.             $this->entityManager->getFilters()->enable('option_nostock_hidden');
  111.         }
  112.         // handleRequestは空のqueryの場合は無視するため
  113.         if ($request->getMethod() === 'GET') {
  114.             $request->query->set('pageno'$request->query->get('pageno'''));
  115.         }
  116.         // searchForm
  117.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  118.         $builder $this->formFactory->createNamedBuilder(''SearchProductType::class);
  119.         if ($request->getMethod() === 'GET') {
  120.             $builder->setMethod('GET');
  121.         }
  122.         $event = new EventArgs(
  123.             [
  124.                 'builder' => $builder,
  125.             ],
  126.             $request
  127.         );
  128.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE);
  129.         /* @var $searchForm \Symfony\Component\Form\FormInterface */
  130.         $searchForm $builder->getForm();
  131.         $searchForm->handleRequest($request);
  132.         // paginator
  133.         $searchData $searchForm->getData();
  134.         $qb $this->productRepository->getQueryBuilderBySearchData($searchData);
  135.         $event = new EventArgs(
  136.             [
  137.                 'searchData' => $searchData,
  138.                 'qb' => $qb,
  139.             ],
  140.             $request
  141.         );
  142.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_SEARCH);
  143.         $searchData $event->getArgument('searchData');
  144.         // 価格帯パラメータを searchData に追加 → Repository側で処理
  145.         $priceMin $request->query->get('price_min');
  146.         $priceMax $request->query->get('price_max');
  147.         if ($priceMin !== null && $priceMin !== '') {
  148.             $searchData['price_min'] = $priceMin;
  149.         }
  150.         if ($priceMax !== null && $priceMax !== '') {
  151.             $searchData['price_max'] = $priceMax;
  152.         }
  153.         // searchData を更新したので qb を再構築
  154.         if (isset($searchData['price_min']) || isset($searchData['price_max'])) {
  155.             $qb $this->productRepository->getQueryBuilderBySearchData($searchData);
  156.         }
  157.         $query $qb->getQuery()
  158.             ->useResultCache(true$this->eccubeConfig['eccube_result_cache_lifetime_short']);
  159.         /** @var SlidingPagination $pagination */
  160.         $pagination $paginator->paginate(
  161.             $query,
  162.             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  163.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
  164.         );
  165.         $ids = [];
  166.         foreach ($pagination as $Product) {
  167.             $ids[] = $Product->getId();
  168.         }
  169.         $ProductsAndClassCategories $this->productRepository->findProductsWithSortedClassCategories($ids'p.id');
  170.         // addCart form
  171.         $forms = [];
  172.         foreach ($pagination as $Product) {
  173.             /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  174.             $builder $this->formFactory->createNamedBuilder(
  175.                 '',
  176.                 AddCartType::class,
  177.                 null,
  178.                 [
  179.                     'product' => $ProductsAndClassCategories[$Product->getId()],
  180.                     'allow_extra_fields' => true,
  181.                 ]
  182.             );
  183.             $addCartForm $builder->getForm();
  184.             $forms[$Product->getId()] = $addCartForm->createView();
  185.         }
  186.         $Category $searchForm->get('category_id')->getData();
  187.         $Maker $searchForm->get('maker_id')->getData();
  188.         return [
  189.             'subtitle' => $this->getPageTitle($searchData),
  190.             'pagination' => $pagination,
  191.             'search_form' => $searchForm->createView(),
  192.             'forms' => $forms,
  193.             'Category' => $Category,
  194.             'Maker' => $Maker,
  195.         ];
  196.     }
  197.     /**
  198.      * 商品詳細画面.
  199.      *
  200.      * @Route("/products/detail/{id}", name="product_detail", methods={"GET"}, requirements={"id" = "\d+"})
  201.      * @Template("Product/detail.twig")
  202.      * @ParamConverter("Product", options={"repository_method" = "findWithSortedClassCategories"})
  203.      *
  204.      * @param Request $request
  205.      * @param Product $Product
  206.      *
  207.      * @return array
  208.      */
  209.     public function detail(Request $requestProduct $Product)
  210.     {
  211.         if (!$this->checkVisibility($Product)) {
  212.             throw new NotFoundHttpException();
  213.         }
  214.         $builder $this->formFactory->createNamedBuilder(
  215.             '',
  216.             AddCartType::class,
  217.             null,
  218.             [
  219.                 'product' => $Product,
  220.                 'id_add_product_id' => false,
  221.             ]
  222.         );
  223.     
  224.         $event = new EventArgs(
  225.             [
  226.                 'builder' => $builder,
  227.                 'Product' => $Product,
  228.             ],
  229.             $request
  230.         );
  231.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE);
  232.         $is_favorite false;
  233.         if ($this->isGranted('ROLE_USER')) {
  234.             $Customer $this->getUser();
  235.             $is_favorite $this->customerFavoriteProductRepository->isFavorite($Customer$Product);
  236.         }
  237.         $color = array();
  238.         if(!empty($Product->getSearchWord())){
  239.             $color unserialize($Product->getSearchWord());
  240.         }
  241.         $pp = array();
  242.         $p_w = array();
  243.         $p_d = array();
  244.         $p_h = array();
  245.         $p_m = array();
  246.         $p_c = array();
  247.         if(!empty($Product->getFreeArea())){
  248.             $pp_price unserialize($Product->getFreeArea());
  249.             foreach($pp_price as $key => $item){
  250.                 if(empty($item['ct'])){ $item['ct'] = 0; }
  251.                 $pp[] = $item;
  252.                 $p_w[$item['w']] = $item['w'];
  253.                 $p_c[$item['c']] = $item['c'];
  254.                 $p_d[$item['d']] = $item['d'];
  255.                 $p_h[$item['h']] = $item['h'];
  256.                 $p_m[$item['m']] = $item['m'];
  257.             }
  258.         }
  259.         $op = array();
  260.         if(!empty($Product->getOptionArea())){
  261.             $op unserialize($Product->getOptionArea());
  262.         }
  263.         $oi = array();
  264.         if(!empty($Product->getOptionItemArea())){
  265.             $oi_tmp unserialize($Product->getOptionItemArea());
  266.             foreach($oi_tmp as $key => $item){
  267.                 $oi[] = $item;
  268.             }
  269.         }
  270.         $ProductClasses $Product->getProductClasses();
  271.         $ProductClass $ProductClasses[0];
  272.         $Configs $this->ConfigRepository->joinMetaKeyFind($Product->getId(),'related_product');
  273.         $meta_array unserialize($Configs["b_meta_content"]);
  274.         $meta_array[] = $Product->getId();
  275.         $related_product $this->productRepository->findBy(["id" => $meta_array,'Status' => 1]);
  276.         $related_keyword $this->ConfigRepository->joinMetaKeyFind($Product->getId(),'related_keyword');
  277.         $base_select1 $this->ConfigRepository->joinMetaKeyFind($Product->getId(),'related_selected1');
  278.         $base_select2 $this->ConfigRepository->joinMetaKeyFind($Product->getId(),'related_selected2');
  279.         $base_select3 $this->ConfigRepository->joinMetaKeyFind($Product->getId(),'related_selected3');
  280.         $related_product1 = array();
  281.         $related_product2 = array();
  282.         $related_product3 = array();
  283.         $registed_select1 = array();
  284.         $registed_select2 = array();
  285.         $registed_select3 = array();
  286.         $rrp = array();
  287.         foreach($related_product as $rp){
  288.             $select_name1 $this->ConfigRepository->joinMetaKeyFind($rp->getId(),'related_selected1');
  289.             $select_name2 $this->ConfigRepository->joinMetaKeyFind($rp->getId(),'related_selected2');
  290.             $select_name3 $this->ConfigRepository->joinMetaKeyFind($rp->getId(),'related_selected3');
  291.             $rrp[] = $rp->getId();
  292.             if(!in_array($select_name1["b_meta_content"],$registed_select1)){
  293.                 $registed_select1[$select_name1["b_meta_content"]] = $select_name1["b_meta_content"];
  294.                 $related_product1[$rp->getId()] = $select_name1["b_meta_content"];
  295.                 if(preg_match("/スタンダード|片側|フラット|ノーマル/",$related_product1[$rp->getId()])){
  296.                     $related_product1[$rp->getId()] = "[1]".$related_product1[$rp->getId()];
  297.                 }
  298.                 if(preg_match("/プレミアム|両側|ラウンド|幅広/",$related_product1[$rp->getId()])){
  299.                     $related_product1[$rp->getId()] = "[2]".$related_product1[$rp->getId()];
  300.                 }
  301.                 if(preg_match("/デラックス|後方|アーチ|外壁接続/",$related_product1[$rp->getId()])){
  302.                     $related_product1[$rp->getId()] = "[3]".$related_product1[$rp->getId()];
  303.                 }
  304.                 if(preg_match("/屋根/",$related_product1[$rp->getId()])){
  305.                     $related_product1[$rp->getId()] = "[4]".$related_product1[$rp->getId()];
  306.                 }
  307.             }
  308.             if(!in_array($select_name2["b_meta_content"],$registed_select2) && $base_select1["b_meta_content"] == $select_name1["b_meta_content"]){
  309.                 $registed_select2[$select_name2["b_meta_content"]] = $select_name2["b_meta_content"];
  310.                 $related_product2[$rp->getId()] = $select_name2["b_meta_content"];
  311.                 if(preg_match("/スタンダード|片側|フラット|ノーマル/",$related_product2[$rp->getId()])){
  312.                     $related_product2[$rp->getId()] = "[1]".$related_product2[$rp->getId()];
  313.                 }
  314.                 if(preg_match("/プレミアム|両側|ラウンド|幅広/",$related_product2[$rp->getId()])){
  315.                     $related_product2[$rp->getId()] = "[2]".$related_product2[$rp->getId()];
  316.                 }
  317.                 if(preg_match("/デラックス|後方|アーチ|外壁接続/",$related_product2[$rp->getId()])){
  318.                     $related_product2[$rp->getId()] = "[3]".$related_product2[$rp->getId()];
  319.                 }
  320.                 if(preg_match("/屋根/",$related_product2[$rp->getId()])){
  321.                     $related_product2[$rp->getId()] = "[4]".$related_product2[$rp->getId()];
  322.                 }
  323.             }
  324.             if(!in_array($select_name3["b_meta_content"],$registed_select3) && $base_select1["b_meta_content"] == $select_name1["b_meta_content"] && $base_select2["b_meta_content"] == $select_name2["b_meta_content"]){
  325.                 $registed_select3[$select_name3["b_meta_content"]] = $select_name3["b_meta_content"];
  326.                 $related_product3[$rp->getId()] = $select_name3["b_meta_content"];
  327.                 if(preg_match("/スタンダード|片側|フラット|ノーマル/",$related_product3[$rp->getId()])){
  328.                     $related_product3[$rp->getId()] = "[1]".$related_product3[$rp->getId()];
  329.                 }
  330.                 if(preg_match("/プレミアム|両側|ラウンド|幅広/",$related_product3[$rp->getId()])){
  331.                     $related_product3[$rp->getId()] = "[2]".$related_product3[$rp->getId()];
  332.                 }
  333.                 if(preg_match("/デラックス|後方|アーチ|外壁接続/",$related_product3[$rp->getId()])){
  334.                     $related_product3[$rp->getId()] = "[3]".$related_product3[$rp->getId()];
  335.                 }
  336.                 if(preg_match("/屋根/",$related_product3[$rp->getId()])){
  337.                     $related_product3[$rp->getId()] = "[4]".$related_product3[$rp->getId()];
  338.                 }
  339.             }
  340.         }
  341.         asort($related_product1,SORT_NATURAL);
  342.         asort($related_product1,SORT_NUMERIC);
  343.         asort($related_product2,SORT_NATURAL);
  344.         asort($related_product2,SORT_NUMERIC);
  345.         asort($related_product3,SORT_NATURAL);
  346.         asort($related_product3,SORT_NUMERIC);
  347.         
  348.         foreach($related_product1 as $rp_id => $rd_value){
  349.             $rd_value preg_replace('/\[[0-9]+\]/'''$rd_value);
  350.             $related_product1[$rp_id] = $rd_value;
  351.         }
  352.         foreach($related_product2 as $rp_id => $rd_value){
  353.             $rd_value preg_replace('/\[[0-9]+\]/'''$rd_value);
  354.             $related_product2[$rp_id] = $rd_value;
  355.         }
  356.         foreach($related_product3 as $rp_id => $rd_value){
  357.             $rd_value preg_replace('/\[[0-9]+\]/'''$rd_value);
  358.             $related_product3[$rp_id] = $rd_value;
  359.         }
  360.         $mitsumori_json = @$_SESSION['mitsumori_json'];
  361.         if(empty($mitsumori_json)){ $mitsumori_json "{product_id:0, pw:'',pd:'',ph:'',pm:'',pc:'',op:['','','','','','','','','','','']}"; }
  362.         $mitsumori_json_obj json_decode($mitsumori_json);
  363.         if(empty($mitsumori_json_obj) || $mitsumori_json_obj->product_id != $Product->getId()){
  364.             $mitsumori_json_obj json_decode("{product_id:0, pw:'',pd:'',ph:'',pm:'',pc:'',op:['','','','','','','','','','','']}");
  365.         }
  366.         return [
  367.             'title' => $this->title,
  368.             'subtitle' => $Product->getName(),
  369.             'form' => $builder->getForm()->createView(),
  370.             'Product' => $Product,
  371.             'color' => $color,
  372.             'pp' => json_encode($pp),
  373.             'base_select1' => @$base_select1["b_meta_content"],
  374.             'base_select2' => @$base_select2["b_meta_content"],
  375.             'base_select3' => @$base_select3["b_meta_content"],
  376.             'related_product1' => $related_product1,
  377.             'related_product2' => $related_product2,
  378.             'related_product3' => $related_product3,
  379.             'mitsumori_json' => $mitsumori_json_obj,
  380.             'p_w' => $p_w,
  381.             'p_d' => $p_d,
  382.             'p_h' => $p_h,
  383.             'p_m' => $p_m,
  384.             'p_c' => $p_c,
  385.             'op' => $op,
  386.             'oi' => $oi,
  387.             'ProductClass' => $ProductClass,
  388.             'is_favorite' => $is_favorite,
  389.         ];
  390.     }
  391.     /**
  392.      * お気に入り追加.
  393.      *
  394.      * @Route("/products/add_favorite/{id}", name="product_add_favorite", requirements={"id" = "\d+"}, methods={"GET", "POST"})
  395.      */
  396.     public function addFavorite(Request $requestProduct $Product)
  397.     {
  398.         $this->checkVisibility($Product);
  399.         $event = new EventArgs(
  400.             [
  401.                 'Product' => $Product,
  402.             ],
  403.             $request
  404.         );
  405.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_INITIALIZE);
  406.         if ($this->isGranted('ROLE_USER')) {
  407.             $Customer $this->getUser();
  408.             $this->customerFavoriteProductRepository->addFavorite($Customer$Product);
  409.             $this->session->getFlashBag()->set('product_detail.just_added_favorite'$Product->getId());
  410.             $event = new EventArgs(
  411.                 [
  412.                     'Product' => $Product,
  413.                 ],
  414.                 $request
  415.             );
  416.             $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE);
  417.             return $this->redirectToRoute('product_detail', ['id' => $Product->getId()]);
  418.         } else {
  419.             // 非会員の場合、ログイン画面を表示
  420.             //  ログイン後の画面遷移先を設定
  421.             $this->setLoginTargetPath($this->generateUrl('product_add_favorite', ['id' => $Product->getId()], UrlGeneratorInterface::ABSOLUTE_URL));
  422.             $this->session->getFlashBag()->set('eccube.add.favorite'true);
  423.             $event = new EventArgs(
  424.                 [
  425.                     'Product' => $Product,
  426.                 ],
  427.                 $request
  428.             );
  429.             $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE);
  430.             return $this->redirectToRoute('mypage_login');
  431.         }
  432.     }
  433.     /**
  434.      * カートに追加.
  435.      *
  436.      * @Route("/products/add_cart/{id}", name="product_add_cart", methods={"POST"}, requirements={"id" = "\d+"})
  437.      */
  438.     public function addCart(Request $requestProduct $Product)
  439.     {
  440.         if(!empty($_POST['mitsumori_json'])){
  441.             $_SESSION['mitsumori_json'] = $_POST['mitsumori_json'];
  442.         }
  443.         // エラーメッセージの配列
  444.         $errorMessages = [];
  445.         if (!$this->checkVisibility($Product)) {
  446.             throw new NotFoundHttpException();
  447.         }
  448.         $builder $this->formFactory->createNamedBuilder(
  449.             '',
  450.             AddCartType::class,
  451.             null,
  452.             [
  453.                 'product' => $Product,
  454.                 'id_add_product_id' => false,
  455.             ]
  456.         );
  457.         $event = new EventArgs(
  458.             [
  459.                 'builder' => $builder,
  460.                 'Product' => $Product,
  461.             ],
  462.             $request
  463.         );
  464.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_CART_ADD_INITIALIZE);
  465.         /* @var $form \Symfony\Component\Form\FormInterface */
  466.         $form $builder->getForm();
  467.         $form->handleRequest($request);
  468.         if (!$form->isValid()) {
  469.             throw new NotFoundHttpException();
  470.         }
  471.         $addCartData $form->getData();
  472.         log_info(
  473.             'カート追加処理開始',
  474.             [
  475.                 'product_id' => $Product->getId(),
  476.                 'product_class_id' => $addCartData['product_class_id'],
  477.                 'quantity' => $addCartData['quantity'],
  478.             ]
  479.         );
  480.         $ProductClass $this->entityManager->getRepository(ProductClass::class)->find($addCartData['product_class_id']);
  481.         $ProductClass->setMitsumoriJSON(@$_POST['mitsumori_json']);
  482.         // カートへ追加
  483.         $this->cartService->addProduct($ProductClass$addCartData['quantity']);
  484.         // 明細の正規化
  485.         $Carts $this->cartService->getCarts();
  486.         foreach ($Carts as $Cart) {
  487.             $result $this->purchaseFlow->validate($Cart, new PurchaseContext($Cart$this->getUser()));
  488.             // 復旧不可のエラーが発生した場合は追加した明細を削除.
  489.             if ($result->hasError()) {
  490.                 $this->cartService->removeProduct($addCartData['product_class_id']);
  491.                 foreach ($result->getErrors() as $error) {
  492.                     $errorMessages[] = $error->getMessage();
  493.                 }
  494.             }
  495.             foreach ($result->getWarning() as $warning) {
  496.                 $errorMessages[] = $warning->getMessage();
  497.             }
  498.         }
  499.         $this->cartService->save();
  500.         log_info(
  501.             'カート追加処理完了',
  502.             [
  503.                 'product_id' => $Product->getId(),
  504.                 'product_class_id' => $addCartData['product_class_id'],
  505.                 'quantity' => $addCartData['quantity'],
  506.             ]
  507.         );
  508.         $event = new EventArgs(
  509.             [
  510.                 'form' => $form,
  511.                 'Product' => $Product,
  512.             ],
  513.             $request
  514.         );
  515.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_CART_ADD_COMPLETE);
  516.         if ($event->getResponse() !== null) {
  517.             return $event->getResponse();
  518.         }
  519.         if ($request->isXmlHttpRequest()) {
  520.             // ajaxでのリクエストの場合は結果をjson形式で返す。
  521.             // 初期化
  522.             $messages = [];
  523.             if (empty($errorMessages)) {
  524.                 // エラーが発生していない場合
  525.                 $done true;
  526.                 array_push($messagestrans('front.product.add_cart_complete'));
  527.             } else {
  528.                 // エラーが発生している場合
  529.                 $done false;
  530.                 $messages $errorMessages;
  531.             }
  532.             return $this->json(['done' => $done'messages' => $messages]);
  533.         } else {
  534.             // ajax以外でのリクエストの場合はカート画面へリダイレクト
  535.             foreach ($errorMessages as $errorMessage) {
  536.                 $this->addRequestError($errorMessage);
  537.             }
  538.             return $this->redirectToRoute('cart');
  539.         }
  540.     }
  541.     /**
  542.      * ページタイトルの設定
  543.      *
  544.      * @param  array|null $searchData
  545.      *
  546.      * @return str
  547.      */
  548.     protected function getPageTitle($searchData)
  549.     {
  550.         if (isset($searchData['name']) && !empty($searchData['name'])) {
  551.             return trans('front.product.search_result');
  552.         } elseif (isset($searchData['category_id']) && $searchData['category_id']) {
  553.             return $searchData['category_id']->getName();
  554.         } else {
  555.             return trans('front.product.all_products');
  556.         }
  557.     }
  558.     /**
  559.      * 閲覧可能な商品かどうかを判定
  560.      *
  561.      * @param Product $Product
  562.      *
  563.      * @return boolean 閲覧可能な場合はtrue
  564.      */
  565.     protected function checkVisibility(Product $Product)
  566.     {
  567.         $is_admin $this->session->has('_security_admin');
  568.         // 管理ユーザの場合はステータスやオプションにかかわらず閲覧可能.
  569.         if (!$is_admin) {
  570.             // 在庫なし商品の非表示オプションが有効な場合.
  571.             // if ($this->BaseInfo->isOptionNostockHidden()) {
  572.             //     if (!$Product->getStockFind()) {
  573.             //         return false;
  574.             //     }
  575.             // }
  576.             // 公開ステータスでない商品は表示しない.
  577.             if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
  578.                 return false;
  579.             }
  580.         }
  581.         return true;
  582.     }
  583. }