app/Customize/Controller/ProductController.php line 227

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.         $query $qb->getQuery()
  145.             ->useResultCache(true$this->eccubeConfig['eccube_result_cache_lifetime_short']);
  146.         /** @var SlidingPagination $pagination */
  147.         $pagination $paginator->paginate(
  148.             $query,
  149.             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  150.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
  151.         );
  152.         $ids = [];
  153.         foreach ($pagination as $Product) {
  154.             $ids[] = $Product->getId();
  155.         }
  156.         $ProductsAndClassCategories $this->productRepository->findProductsWithSortedClassCategories($ids'p.id');
  157.         // addCart form
  158.         $forms = [];
  159.         foreach ($pagination as $Product) {
  160.             /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  161.             $builder $this->formFactory->createNamedBuilder(
  162.                 '',
  163.                 AddCartType::class,
  164.                 null,
  165.                 [
  166.                     'product' => $ProductsAndClassCategories[$Product->getId()],
  167.                     'allow_extra_fields' => true,
  168.                 ]
  169.             );
  170.             $addCartForm $builder->getForm();
  171.             $forms[$Product->getId()] = $addCartForm->createView();
  172.         }
  173.         $Category $searchForm->get('category_id')->getData();
  174.         $Maker $searchForm->get('maker_id')->getData();
  175.         return [
  176.             'subtitle' => $this->getPageTitle($searchData),
  177.             'pagination' => $pagination,
  178.             'search_form' => $searchForm->createView(),
  179.             'forms' => $forms,
  180.             'Category' => $Category,
  181.             'Maker' => $Maker,
  182.         ];
  183.     }
  184.     /**
  185.      * 商品詳細画面.
  186.      *
  187.      * @Route("/products/detail/{id}", name="product_detail", methods={"GET"}, requirements={"id" = "\d+"})
  188.      * @Template("Product/detail.twig")
  189.      * @ParamConverter("Product", options={"repository_method" = "findWithSortedClassCategories"})
  190.      *
  191.      * @param Request $request
  192.      * @param Product $Product
  193.      *
  194.      * @return array
  195.      */
  196.     public function detail(Request $requestProduct $Product)
  197.     {
  198.         if (!$this->checkVisibility($Product)) {
  199.             throw new NotFoundHttpException();
  200.         }
  201.         $builder $this->formFactory->createNamedBuilder(
  202.             '',
  203.             AddCartType::class,
  204.             null,
  205.             [
  206.                 'product' => $Product,
  207.                 'id_add_product_id' => false,
  208.             ]
  209.         );
  210.     
  211.         $event = new EventArgs(
  212.             [
  213.                 'builder' => $builder,
  214.                 'Product' => $Product,
  215.             ],
  216.             $request
  217.         );
  218.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE);
  219.         $is_favorite false;
  220.         if ($this->isGranted('ROLE_USER')) {
  221.             $Customer $this->getUser();
  222.             $is_favorite $this->customerFavoriteProductRepository->isFavorite($Customer$Product);
  223.         }
  224.         $color = array();
  225.         if(!empty($Product->getSearchWord())){
  226.             $color unserialize($Product->getSearchWord());
  227.         }
  228.         $pp = array();
  229.         $p_w = array();
  230.         $p_d = array();
  231.         $p_h = array();
  232.         $p_m = array();
  233.         $p_c = array();
  234.         if(!empty($Product->getFreeArea())){
  235.             $pp_price unserialize($Product->getFreeArea());
  236.             foreach($pp_price as $key => $item){
  237.                 if(empty($item['ct'])){ $item['ct'] = 0; }
  238.                 $pp[] = $item;
  239.                 $p_w[$item['w']] = $item['w'];
  240.                 $p_c[$item['c']] = $item['c'];
  241.                 $p_d[$item['d']] = $item['d'];
  242.                 $p_h[$item['h']] = $item['h'];
  243.                 $p_m[$item['m']] = $item['m'];
  244.             }
  245.         }
  246.         $op = array();
  247.         if(!empty($Product->getOptionArea())){
  248.             $op unserialize($Product->getOptionArea());
  249.         }
  250.         $oi = array();
  251.         if(!empty($Product->getOptionItemArea())){
  252.             $oi_tmp unserialize($Product->getOptionItemArea());
  253.             foreach($oi_tmp as $key => $item){
  254.                 $oi[] = $item;
  255.             }
  256.         }
  257.         $ProductClasses $Product->getProductClasses();
  258.         $ProductClass $ProductClasses[0];
  259.         $Configs $this->ConfigRepository->joinMetaKeyFind($Product->getId(),'related_product');
  260.         $meta_array unserialize($Configs["b_meta_content"]);
  261.         $meta_array[] = $Product->getId();
  262.         $related_product $this->productRepository->findBy(["id" => $meta_array,'Status' => 1]);
  263.         $related_keyword $this->ConfigRepository->joinMetaKeyFind($Product->getId(),'related_keyword');
  264.         $base_select1 $this->ConfigRepository->joinMetaKeyFind($Product->getId(),'related_selected1');
  265.         $base_select2 $this->ConfigRepository->joinMetaKeyFind($Product->getId(),'related_selected2');
  266.         $base_select3 $this->ConfigRepository->joinMetaKeyFind($Product->getId(),'related_selected3');
  267.         $related_product1 = array();
  268.         $related_product2 = array();
  269.         $related_product3 = array();
  270.         $registed_select1 = array();
  271.         $registed_select2 = array();
  272.         $registed_select3 = array();
  273.         $rrp = array();
  274.         foreach($related_product as $rp){
  275.             $select_name1 $this->ConfigRepository->joinMetaKeyFind($rp->getId(),'related_selected1');
  276.             $select_name2 $this->ConfigRepository->joinMetaKeyFind($rp->getId(),'related_selected2');
  277.             $select_name3 $this->ConfigRepository->joinMetaKeyFind($rp->getId(),'related_selected3');
  278.             $rrp[] = $rp->getId();
  279.             if(!in_array($select_name1["b_meta_content"],$registed_select1)){
  280.                 $registed_select1[$select_name1["b_meta_content"]] = $select_name1["b_meta_content"];
  281.                 $related_product1[$rp->getId()] = $select_name1["b_meta_content"];
  282.                 if(preg_match("/スタンダード|片側|フラット|ノーマル/",$related_product1[$rp->getId()])){
  283.                     $related_product1[$rp->getId()] = "[1]".$related_product1[$rp->getId()];
  284.                 }
  285.                 if(preg_match("/プレミアム|両側|ラウンド|幅広/",$related_product1[$rp->getId()])){
  286.                     $related_product1[$rp->getId()] = "[2]".$related_product1[$rp->getId()];
  287.                 }
  288.                 if(preg_match("/デラックス|後方|アーチ|外壁接続/",$related_product1[$rp->getId()])){
  289.                     $related_product1[$rp->getId()] = "[3]".$related_product1[$rp->getId()];
  290.                 }
  291.                 if(preg_match("/屋根/",$related_product1[$rp->getId()])){
  292.                     $related_product1[$rp->getId()] = "[4]".$related_product1[$rp->getId()];
  293.                 }
  294.             }
  295.             if(!in_array($select_name2["b_meta_content"],$registed_select2) && $base_select1["b_meta_content"] == $select_name1["b_meta_content"]){
  296.                 $registed_select2[$select_name2["b_meta_content"]] = $select_name2["b_meta_content"];
  297.                 $related_product2[$rp->getId()] = $select_name2["b_meta_content"];
  298.                 if(preg_match("/スタンダード|片側|フラット|ノーマル/",$related_product2[$rp->getId()])){
  299.                     $related_product2[$rp->getId()] = "[1]".$related_product2[$rp->getId()];
  300.                 }
  301.                 if(preg_match("/プレミアム|両側|ラウンド|幅広/",$related_product2[$rp->getId()])){
  302.                     $related_product2[$rp->getId()] = "[2]".$related_product2[$rp->getId()];
  303.                 }
  304.                 if(preg_match("/デラックス|後方|アーチ|外壁接続/",$related_product2[$rp->getId()])){
  305.                     $related_product2[$rp->getId()] = "[3]".$related_product2[$rp->getId()];
  306.                 }
  307.                 if(preg_match("/屋根/",$related_product2[$rp->getId()])){
  308.                     $related_product2[$rp->getId()] = "[4]".$related_product2[$rp->getId()];
  309.                 }
  310.             }
  311.             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"]){
  312.                 $registed_select3[$select_name3["b_meta_content"]] = $select_name3["b_meta_content"];
  313.                 $related_product3[$rp->getId()] = $select_name3["b_meta_content"];
  314.                 if(preg_match("/スタンダード|片側|フラット|ノーマル/",$related_product3[$rp->getId()])){
  315.                     $related_product3[$rp->getId()] = "[1]".$related_product3[$rp->getId()];
  316.                 }
  317.                 if(preg_match("/プレミアム|両側|ラウンド|幅広/",$related_product3[$rp->getId()])){
  318.                     $related_product3[$rp->getId()] = "[2]".$related_product3[$rp->getId()];
  319.                 }
  320.                 if(preg_match("/デラックス|後方|アーチ|外壁接続/",$related_product3[$rp->getId()])){
  321.                     $related_product3[$rp->getId()] = "[3]".$related_product3[$rp->getId()];
  322.                 }
  323.                 if(preg_match("/屋根/",$related_product3[$rp->getId()])){
  324.                     $related_product3[$rp->getId()] = "[4]".$related_product3[$rp->getId()];
  325.                 }
  326.             }
  327.         }
  328.         asort($related_product1,SORT_NATURAL);
  329.         asort($related_product1,SORT_NUMERIC);
  330.         asort($related_product2,SORT_NATURAL);
  331.         asort($related_product2,SORT_NUMERIC);
  332.         asort($related_product3,SORT_NATURAL);
  333.         asort($related_product3,SORT_NUMERIC);
  334.         
  335.         foreach($related_product1 as $rp_id => $rd_value){
  336.             $rd_value preg_replace('/\[[0-9]+\]/'''$rd_value);
  337.             $related_product1[$rp_id] = $rd_value;
  338.         }
  339.         foreach($related_product2 as $rp_id => $rd_value){
  340.             $rd_value preg_replace('/\[[0-9]+\]/'''$rd_value);
  341.             $related_product2[$rp_id] = $rd_value;
  342.         }
  343.         foreach($related_product3 as $rp_id => $rd_value){
  344.             $rd_value preg_replace('/\[[0-9]+\]/'''$rd_value);
  345.             $related_product3[$rp_id] = $rd_value;
  346.         }
  347.         $mitsumori_json = @$_SESSION['mitsumori_json'];
  348.         if(empty($mitsumori_json)){ $mitsumori_json "{product_id:0, pw:'',pd:'',ph:'',pm:'',pc:'',op:['','','','','','','','','','','']}"; }
  349.         $mitsumori_json_obj json_decode($mitsumori_json);
  350.         if(empty($mitsumori_json_obj) || $mitsumori_json_obj->product_id != $Product->getId()){
  351.             $mitsumori_json_obj json_decode("{product_id:0, pw:'',pd:'',ph:'',pm:'',pc:'',op:['','','','','','','','','','','']}");
  352.         }
  353.         return [
  354.             'title' => $this->title,
  355.             'subtitle' => $Product->getName(),
  356.             'form' => $builder->getForm()->createView(),
  357.             'Product' => $Product,
  358.             'color' => $color,
  359.             'pp' => json_encode($pp),
  360.             'base_select1' => @$base_select1["b_meta_content"],
  361.             'base_select2' => @$base_select2["b_meta_content"],
  362.             'base_select3' => @$base_select3["b_meta_content"],
  363.             'related_product1' => $related_product1,
  364.             'related_product2' => $related_product2,
  365.             'related_product3' => $related_product3,
  366.             'mitsumori_json' => $mitsumori_json_obj,
  367.             'p_w' => $p_w,
  368.             'p_d' => $p_d,
  369.             'p_h' => $p_h,
  370.             'p_m' => $p_m,
  371.             'p_c' => $p_c,
  372.             'op' => $op,
  373.             'oi' => $oi,
  374.             'ProductClass' => $ProductClass,
  375.             'is_favorite' => $is_favorite,
  376.         ];
  377.     }
  378.     /**
  379.      * お気に入り追加.
  380.      *
  381.      * @Route("/products/add_favorite/{id}", name="product_add_favorite", requirements={"id" = "\d+"}, methods={"GET", "POST"})
  382.      */
  383.     public function addFavorite(Request $requestProduct $Product)
  384.     {
  385.         $this->checkVisibility($Product);
  386.         $event = new EventArgs(
  387.             [
  388.                 'Product' => $Product,
  389.             ],
  390.             $request
  391.         );
  392.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_INITIALIZE);
  393.         if ($this->isGranted('ROLE_USER')) {
  394.             $Customer $this->getUser();
  395.             $this->customerFavoriteProductRepository->addFavorite($Customer$Product);
  396.             $this->session->getFlashBag()->set('product_detail.just_added_favorite'$Product->getId());
  397.             $event = new EventArgs(
  398.                 [
  399.                     'Product' => $Product,
  400.                 ],
  401.                 $request
  402.             );
  403.             $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE);
  404.             return $this->redirectToRoute('product_detail', ['id' => $Product->getId()]);
  405.         } else {
  406.             // 非会員の場合、ログイン画面を表示
  407.             //  ログイン後の画面遷移先を設定
  408.             $this->setLoginTargetPath($this->generateUrl('product_add_favorite', ['id' => $Product->getId()], UrlGeneratorInterface::ABSOLUTE_URL));
  409.             $this->session->getFlashBag()->set('eccube.add.favorite'true);
  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('mypage_login');
  418.         }
  419.     }
  420.     /**
  421.      * カートに追加.
  422.      *
  423.      * @Route("/products/add_cart/{id}", name="product_add_cart", methods={"POST"}, requirements={"id" = "\d+"})
  424.      */
  425.     public function addCart(Request $requestProduct $Product)
  426.     {
  427.         if(!empty($_POST['mitsumori_json'])){
  428.             $_SESSION['mitsumori_json'] = $_POST['mitsumori_json'];
  429.         }
  430.         // エラーメッセージの配列
  431.         $errorMessages = [];
  432.         if (!$this->checkVisibility($Product)) {
  433.             throw new NotFoundHttpException();
  434.         }
  435.         $builder $this->formFactory->createNamedBuilder(
  436.             '',
  437.             AddCartType::class,
  438.             null,
  439.             [
  440.                 'product' => $Product,
  441.                 'id_add_product_id' => false,
  442.             ]
  443.         );
  444.         $event = new EventArgs(
  445.             [
  446.                 'builder' => $builder,
  447.                 'Product' => $Product,
  448.             ],
  449.             $request
  450.         );
  451.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_CART_ADD_INITIALIZE);
  452.         /* @var $form \Symfony\Component\Form\FormInterface */
  453.         $form $builder->getForm();
  454.         $form->handleRequest($request);
  455.         if (!$form->isValid()) {
  456.             throw new NotFoundHttpException();
  457.         }
  458.         $addCartData $form->getData();
  459.         log_info(
  460.             'カート追加処理開始',
  461.             [
  462.                 'product_id' => $Product->getId(),
  463.                 'product_class_id' => $addCartData['product_class_id'],
  464.                 'quantity' => $addCartData['quantity'],
  465.             ]
  466.         );
  467.         $ProductClass $this->entityManager->getRepository(ProductClass::class)->find($addCartData['product_class_id']);
  468.         $ProductClass->setMitsumoriJSON(@$_POST['mitsumori_json']);
  469.         // カートへ追加
  470.         $this->cartService->addProduct($ProductClass$addCartData['quantity']);
  471.         // 明細の正規化
  472.         $Carts $this->cartService->getCarts();
  473.         foreach ($Carts as $Cart) {
  474.             $result $this->purchaseFlow->validate($Cart, new PurchaseContext($Cart$this->getUser()));
  475.             // 復旧不可のエラーが発生した場合は追加した明細を削除.
  476.             if ($result->hasError()) {
  477.                 $this->cartService->removeProduct($addCartData['product_class_id']);
  478.                 foreach ($result->getErrors() as $error) {
  479.                     $errorMessages[] = $error->getMessage();
  480.                 }
  481.             }
  482.             foreach ($result->getWarning() as $warning) {
  483.                 $errorMessages[] = $warning->getMessage();
  484.             }
  485.         }
  486.         $this->cartService->save();
  487.         log_info(
  488.             'カート追加処理完了',
  489.             [
  490.                 'product_id' => $Product->getId(),
  491.                 'product_class_id' => $addCartData['product_class_id'],
  492.                 'quantity' => $addCartData['quantity'],
  493.             ]
  494.         );
  495.         $event = new EventArgs(
  496.             [
  497.                 'form' => $form,
  498.                 'Product' => $Product,
  499.             ],
  500.             $request
  501.         );
  502.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_CART_ADD_COMPLETE);
  503.         if ($event->getResponse() !== null) {
  504.             return $event->getResponse();
  505.         }
  506.         if ($request->isXmlHttpRequest()) {
  507.             // ajaxでのリクエストの場合は結果をjson形式で返す。
  508.             // 初期化
  509.             $messages = [];
  510.             if (empty($errorMessages)) {
  511.                 // エラーが発生していない場合
  512.                 $done true;
  513.                 array_push($messagestrans('front.product.add_cart_complete'));
  514.             } else {
  515.                 // エラーが発生している場合
  516.                 $done false;
  517.                 $messages $errorMessages;
  518.             }
  519.             return $this->json(['done' => $done'messages' => $messages]);
  520.         } else {
  521.             // ajax以外でのリクエストの場合はカート画面へリダイレクト
  522.             foreach ($errorMessages as $errorMessage) {
  523.                 $this->addRequestError($errorMessage);
  524.             }
  525.             return $this->redirectToRoute('cart');
  526.         }
  527.     }
  528.     /**
  529.      * ページタイトルの設定
  530.      *
  531.      * @param  array|null $searchData
  532.      *
  533.      * @return str
  534.      */
  535.     protected function getPageTitle($searchData)
  536.     {
  537.         if (isset($searchData['name']) && !empty($searchData['name'])) {
  538.             return trans('front.product.search_result');
  539.         } elseif (isset($searchData['category_id']) && $searchData['category_id']) {
  540.             return $searchData['category_id']->getName();
  541.         } else {
  542.             return trans('front.product.all_products');
  543.         }
  544.     }
  545.     /**
  546.      * 閲覧可能な商品かどうかを判定
  547.      *
  548.      * @param Product $Product
  549.      *
  550.      * @return boolean 閲覧可能な場合はtrue
  551.      */
  552.     protected function checkVisibility(Product $Product)
  553.     {
  554.         $is_admin $this->session->has('_security_admin');
  555.         // 管理ユーザの場合はステータスやオプションにかかわらず閲覧可能.
  556.         if (!$is_admin) {
  557.             // 在庫なし商品の非表示オプションが有効な場合.
  558.             // if ($this->BaseInfo->isOptionNostockHidden()) {
  559.             //     if (!$Product->getStockFind()) {
  560.             //         return false;
  561.             //     }
  562.             // }
  563.             // 公開ステータスでない商品は表示しない.
  564.             if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
  565.                 return false;
  566.             }
  567.         }
  568.         return true;
  569.     }
  570. }