src/Eccube/Controller/ProductController.php line 193

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 Eccube\Controller;
  13. use Eccube\Entity\BaseInfo;
  14. use Eccube\Entity\Master\ProductStatus;
  15. use Eccube\Entity\Product;
  16. use Eccube\Event\EccubeEvents;
  17. use Eccube\Event\EventArgs;
  18. use Eccube\Form\Type\AddCartType;
  19. use Eccube\Form\Type\Master\ProductListMaxType;
  20. use Eccube\Form\Type\Master\ProductListOrderByType;
  21. use Eccube\Form\Type\SearchProductType;
  22. use Eccube\Repository\BaseInfoRepository;
  23. use Eccube\Repository\CustomerFavoriteProductRepository;
  24. use Eccube\Repository\Master\ProductListMaxRepository;
  25. use Eccube\Repository\ProductRepository;
  26. use Eccube\Repository\TagRepository;
  27. use Eccube\Repository\CategoryRepository;
  28. use Eccube\Service\CartService;
  29. use Eccube\Service\PurchaseFlow\PurchaseContext;
  30. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  31. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  32. use Knp\Component\Pager\PaginatorInterface;
  33. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  34. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  35. use Symfony\Component\HttpFoundation\Request;
  36. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  37. use Symfony\Component\Routing\Annotation\Route;
  38. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  39. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  40. use Plugin\BrandManager\Repository\BrandRepository;
  41. use Plugin\TasteManager\Repository\TasteRepository;
  42. class ProductController extends AbstractController
  43. {
  44.     /**
  45.      * @var PurchaseFlow
  46.      */
  47.     protected $purchaseFlow;
  48.     /**
  49.      * @var CustomerFavoriteProductRepository
  50.      */
  51.     protected $customerFavoriteProductRepository;
  52.     /**
  53.      * @var CartService
  54.      */
  55.     protected $cartService;
  56.     /**
  57.      * @var ProductRepository
  58.      */
  59.     protected $productRepository;
  60.     protected $tagRepository;
  61.     /**
  62.      * @var CategoryRepository
  63.      */
  64.     protected $categoryRepository;
  65.     protected $brandRepository;
  66.     protected $tasteRepository;
  67.     
  68.     /**
  69.      * @var BaseInfo
  70.      */
  71.     protected $BaseInfo;
  72.     /**
  73.      * @var AuthenticationUtils
  74.      */
  75.     protected $helper;
  76.     /**
  77.      * @var ProductListMaxRepository
  78.      */
  79.     protected $productListMaxRepository;
  80.     private $title '';
  81.     /**
  82.      * ProductController constructor.
  83.      *
  84.      * @param PurchaseFlow $cartPurchaseFlow
  85.      * @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
  86.      * @param CartService $cartService
  87.      * @param ProductRepository $productRepository
  88.      * @param BaseInfoRepository $baseInfoRepository
  89.      * @param AuthenticationUtils $helper
  90.      * @param ProductListMaxRepository $productListMaxRepository
  91.      */
  92.     public function __construct(
  93.         PurchaseFlow $cartPurchaseFlow,
  94.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  95.         CartService $cartService,
  96.         ProductRepository $productRepository,
  97.         TagRepository $tagRepository,
  98.         CategoryRepository $categoryRepository,
  99.         BrandRepository $brandRepository,
  100.         TasteRepository $tasteRepository,
  101.         BaseInfoRepository $baseInfoRepository,
  102.         AuthenticationUtils $helper,
  103.         ProductListMaxRepository $productListMaxRepository
  104.     ) {
  105.         $this->purchaseFlow $cartPurchaseFlow;
  106.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  107.         $this->cartService $cartService;
  108.         $this->productRepository $productRepository;
  109.         $this->tagRepository $tagRepository;
  110.         $this->categoryRepository $categoryRepository;
  111.         $this->brandRepository $brandRepository;
  112.         $this->tasteRepository $tasteRepository;
  113.         $this->BaseInfo $baseInfoRepository->get();
  114.         $this->helper $helper;
  115.         $this->productListMaxRepository $productListMaxRepository;
  116.     }
  117.     /**
  118.      * 商品一覧画面.
  119.      *
  120.      * @Route("/products/list", name="product_list", methods={"GET"})
  121.      * @Template("Product/list.twig")
  122.      */
  123.     public function index(Request $requestPaginatorInterface $paginator)
  124.     {
  125.         // Doctrine SQLFilter
  126.         if ($this->BaseInfo->isOptionNostockHidden()) {
  127.             $this->entityManager->getFilters()->enable('option_nostock_hidden');
  128.         }
  129.         // handleRequestは空のqueryの場合は無視するため
  130.         if ($request->getMethod() === 'GET') {
  131.             $request->query->set('pageno'$request->query->get('pageno'''));
  132.         }
  133.         // searchForm
  134.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  135.         $builder $this->formFactory->createNamedBuilder(''SearchProductType::class);
  136.         if ($request->getMethod() === 'GET') {
  137.             $builder->setMethod('GET');
  138.         }
  139.         $event = new EventArgs(
  140.             [
  141.                 'builder' => $builder,
  142.             ],
  143.             $request
  144.         );
  145.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE$event);
  146.         /* @var $searchForm \Symfony\Component\Form\FormInterface */
  147.         $searchForm $builder->getForm();
  148.         $searchForm->handleRequest($request);
  149.         // paginator
  150.         $searchData $searchForm->getData();
  151.         $qb $this->productRepository->getQueryBuilderBySearchData($searchData);
  152.         $event = new EventArgs(
  153.             [
  154.                 'searchData' => $searchData,
  155.                 'qb' => $qb,
  156.             ],
  157.             $request
  158.         );
  159.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_SEARCH$event);
  160.         $searchData $event->getArgument('searchData');
  161.         $query $qb->getQuery()
  162.             ->useResultCache(true$this->eccubeConfig['eccube_result_cache_lifetime_short']);
  163.         /** @var SlidingPagination $pagination */
  164.         $pagination $paginator->paginate(
  165.             $query,
  166.             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  167.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
  168.         );
  169.         $ids = [];
  170.         foreach ($pagination as $Product) {
  171.             $ids[] = $Product->getId();
  172.         }
  173.         $ProductsAndClassCategories $this->productRepository->findProductsWithSortedClassCategories($ids'p.id');
  174.         // addCart form
  175.         $forms = [];
  176.         foreach ($pagination as $Product) {
  177.             /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  178.             $builder $this->formFactory->createNamedBuilder(
  179.                 '',
  180.                 AddCartType::class,
  181.                 null,
  182.                 [
  183.                     'product' => $ProductsAndClassCategories[$Product->getId()],
  184.                     'allow_extra_fields' => true,
  185.                 ]
  186.             );
  187.             $addCartForm $builder->getForm();
  188.             $forms[$Product->getId()] = $addCartForm->createView();
  189.         }
  190.         // 表示件数
  191.         $builder $this->formFactory->createNamedBuilder(
  192.             'disp_number',
  193.             ProductListMaxType::class,
  194.             null,
  195.             [
  196.                 'required' => false,
  197.                 'allow_extra_fields' => true,
  198.             ]
  199.         );
  200.         if ($request->getMethod() === 'GET') {
  201.             $builder->setMethod('GET');
  202.         }
  203.         $event = new EventArgs(
  204.             [
  205.                 'builder' => $builder,
  206.             ],
  207.             $request
  208.         );
  209.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_DISP$event);
  210.         $dispNumberForm $builder->getForm();
  211.         $dispNumberForm->handleRequest($request);
  212.         // ソート順
  213.         $builder $this->formFactory->createNamedBuilder(
  214.             'orderby',
  215.             ProductListOrderByType::class,
  216.             null,
  217.             [
  218.                 'required' => false,
  219.                 'allow_extra_fields' => true,
  220.             ]
  221.         );
  222.         if ($request->getMethod() === 'GET') {
  223.             $builder->setMethod('GET');
  224.         }
  225.         $event = new EventArgs(
  226.             [
  227.                 'builder' => $builder,
  228.             ],
  229.             $request
  230.         );
  231.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_ORDER$event);
  232.         $orderByForm $builder->getForm();
  233.         $orderByForm->handleRequest($request);
  234.         $Category $searchForm->get('category_id')->getData();
  235.         
  236.         // 現在の検索条件
  237.         $s_search = array();
  238.         $s_category_id $request->query->get('category_id');
  239.         $s_category_ids preg_split('/\-/'$request->query->get('category_ids'), 0PREG_SPLIT_NO_EMPTY);
  240.         $s_brand_ids preg_split('/\-/'$request->query->get('brand_ids'), 0PREG_SPLIT_NO_EMPTY);
  241.         $s_taste_ids preg_split('/\-/'$request->query->get('taste_ids'), 0PREG_SPLIT_NO_EMPTY);
  242.         $s_tag_id $request->query->get('tag_id');
  243.         $s_name $request->query->get('name');
  244.         
  245.         $s_params $_GET;
  246.         unset($s_params['category_id']);
  247.         unset($s_params['category_ids']);
  248.         unset($s_params['name']);
  249.         
  250.         /*if($s_category_id){
  251.           $c = $this->categoryRepository->find($s_category_id);
  252.           if($c){
  253.             $s_search[] = array(
  254.                 'name'=>$c->getName(),
  255.                 'link'=>$this->make_search_link($request, 'category_id', $s_category_id),
  256.             );
  257.           }
  258.         }*/
  259.         if($s_category_id){
  260.           if(!is_array($s_category_ids)){
  261.             $s_category_ids = array($s_category_id);
  262.           }else{
  263.             $s_category_ids[] = $s_category_id;
  264.           }
  265.         }
  266.         
  267.         if($s_category_ids && is_array($s_category_ids)){
  268.           foreach($s_category_ids as $cid){
  269.             $c $this->categoryRepository->find($cid);
  270.             if($c){
  271.               $s_search[] = array(
  272.                   'name'=>$c->getName(),
  273.                   'link'=>$this->make_search_link($request'category_ids'$cid),
  274.               );
  275.             }
  276.           }
  277.         }
  278.         if($s_brand_ids && is_array($s_brand_ids)){
  279.           foreach($s_brand_ids as $cid){
  280.             $c $this->brandRepository->find($cid);
  281.             if($c){
  282.               $s_search[] = array(
  283.                   'name'=>$c->getName(),
  284.                   'link'=>$this->make_search_link($request'brand_ids'$cid),
  285.               );
  286.             }
  287.           }
  288.         }
  289.         if($s_taste_ids && is_array($s_taste_ids)){
  290.           foreach($s_taste_ids as $cid){
  291.             $c $this->tasteRepository->find($cid);
  292.             if($c){
  293.               $s_search[] = array(
  294.                   'name'=>$c->getName(),
  295.                   'link'=>$this->make_search_link($request'taste_ids'$cid),
  296.               );
  297.             }
  298.           }
  299.         }
  300.         
  301.         if($s_tag_id){
  302.           
  303.           $tag $this->tagRepository->find($s_tag_id);
  304.           if($tag){
  305.             $s_search[] = array(
  306.               'name'=>$tag->getName(),
  307.               'link'=>$this->make_search_link($request'tag'$s_tag_id),
  308.             );
  309.           }
  310.         }
  311.         if($s_name){
  312.           $s_search[] = array(
  313.               'name'=>$s_name,
  314.               'link'=>$this->make_search_link($request'name'$s_name),
  315.           );
  316.         }
  317.         
  318.         // 検索タイトル
  319.         /*
  320.         $search_title_arr = array();
  321.         foreach($s_search as $s){
  322.           $search_title_arr[] = $s['name']; 
  323.         }
  324.         $search_title = implode(', ', $search_title_arr);
  325.         if(!$search_title){
  326.           $search_title = '全商品';
  327.         }*/
  328.         
  329.         return [
  330.             'subtitle' => $this->getPageTitle($searchData),
  331.             'pagination' => $pagination,
  332.             'search_form' => $searchForm->createView(),
  333.             'disp_number_form' => $dispNumberForm->createView(),
  334.             'order_by_form' => $orderByForm->createView(),
  335.             'forms' => $forms,
  336.             'Category' => $Category,
  337.             's_category_id' => $s_category_id,
  338.             's_category_ids' => $s_category_ids,
  339.             's_brand_ids' => $s_brand_ids,
  340.             's_taste_ids' => $s_taste_ids,
  341.             's_name' => $s_name,
  342.             's_search' => $s_search,
  343.             //'search_title' => $search_title,
  344.         ];
  345.     }
  346.     
  347.     public function make_search_link($request$key$val){
  348.       
  349.       $s_category_id $request->query->get('category_id');
  350.       $s_category_ids $request->query->get('category_ids');
  351.       $s_brand_ids $request->query->get('brand_ids');
  352.       $s_taste_ids $request->query->get('taste_ids');
  353.       $s_tag_id $request->query->get('tag_id');
  354.       $s_name $request->query->get('name');
  355.       
  356.       if($s_category_id){
  357.         if($s_category_ids){
  358.           $s_category_ids .= '-'.$s_category_id;
  359.         }else{
  360.           $s_category_ids $s_category_id;
  361.         }
  362.       }
  363.       
  364.       $s_params $_GET;
  365.       /*unset($s_params['category_id']);
  366.       unset($s_params['category_ids']);
  367.       unset($s_params['brand_ids']);
  368.       unset($s_params['taste_ids']);
  369.       unset($s_params['tag_id']);
  370.       unset($s_params['name']);
  371.       */
  372.       
  373.       if($key==='category_ids'){
  374.         $tmp explode('-'$s_category_ids);
  375.         foreach($tmp as $k=>$v){
  376.           if($v==$val){
  377.             unset($tmp[$k]);
  378.           }
  379.         }
  380.         $s_params['category_ids'] = implode('-'$tmp);
  381.       }
  382.       
  383.       if($key==='brand_ids'){
  384.         $tmp explode('-'$s_brand_ids);
  385.         foreach($tmp as $k=>$v){
  386.           if($v==$val){
  387.             unset($tmp[$k]);
  388.           }
  389.         }
  390.         $s_params['brand_ids'] = implode('-'$tmp);
  391.       }
  392.       
  393.       if($key==='taste_ids'){
  394.         $tmp explode('-'$s_taste_ids);
  395.         foreach($tmp as $k=>$v){
  396.           if($v==$val){
  397.             unset($tmp[$k]);
  398.           }
  399.         }
  400.         $s_params['taste_ids'] = implode('-'$tmp);
  401.       }
  402.       
  403.       if($key==='name'){
  404.         unset($s_params['name']);
  405.       }
  406.       
  407.       if($key==='tag_id'){
  408.         unset($s_params['tag_id']);
  409.       }
  410.       
  411.       foreach($s_params as $k=>$v){
  412.         if($v===''){
  413.           unset($s_params[$k]);
  414.         }
  415.       }
  416.       
  417.       $link '/products/list?'.http_build_query($s_params);
  418.       return $link;
  419.     }
  420.     /**
  421.      * 商品詳細画面.
  422.      *
  423.      * @Route("/products/detail/{id}", name="product_detail", methods={"GET"}, requirements={"id" = "\d+"})
  424.      * @Template("Product/detail.twig")
  425.      * @ParamConverter("Product", options={"repository_method" = "findWithSortedClassCategories"})
  426.      *
  427.      * @param Request $request
  428.      * @param Product $Product
  429.      *
  430.      * @return array
  431.      */
  432.     public function detail(Request $requestProduct $Product)
  433.     {
  434.         if (!$this->checkVisibility($Product)) {
  435.             throw new NotFoundHttpException();
  436.         }
  437.         $builder $this->formFactory->createNamedBuilder(
  438.             '',
  439.             AddCartType::class,
  440.             null,
  441.             [
  442.                 'product' => $Product,
  443.                 'id_add_product_id' => false,
  444.             ]
  445.         );
  446.         $event = new EventArgs(
  447.             [
  448.                 'builder' => $builder,
  449.                 'Product' => $Product,
  450.             ],
  451.             $request
  452.         );
  453.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE$event);
  454.         $is_favorite false;
  455.         if ($this->isGranted('ROLE_USER')) {
  456.             $Customer $this->getUser();
  457.             $is_favorite $this->customerFavoriteProductRepository->isFavorite($Customer$Product);
  458.         }
  459.         return [
  460.             'title' => $this->title,
  461.             'subtitle' => $Product->getName(),
  462.             'form' => $builder->getForm()->createView(),
  463.             'Product' => $Product,
  464.             'is_favorite' => $is_favorite,
  465.         ];
  466.     }
  467.     /**
  468.      * お気に入り追加.
  469.      *
  470.      * @Route("/products/add_favorite/{id}", name="product_add_favorite", requirements={"id" = "\d+"}, methods={"GET", "POST"})
  471.      */
  472.     public function addFavorite(Request $requestProduct $Product)
  473.     {
  474.         $this->checkVisibility($Product);
  475.         $event = new EventArgs(
  476.             [
  477.                 'Product' => $Product,
  478.             ],
  479.             $request
  480.         );
  481.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_INITIALIZE$event);
  482.         if ($this->isGranted('ROLE_USER')) {
  483.             $Customer $this->getUser();
  484.             $this->customerFavoriteProductRepository->addFavorite($Customer$Product);
  485.             $this->session->getFlashBag()->set('product_detail.just_added_favorite'$Product->getId());
  486.             $event = new EventArgs(
  487.                 [
  488.                     'Product' => $Product,
  489.                 ],
  490.                 $request
  491.             );
  492.             $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE$event);
  493.             return $this->redirectToRoute('product_detail', ['id' => $Product->getId()]);
  494.         } else {
  495.             // 非会員の場合、ログイン画面を表示
  496.             //  ログイン後の画面遷移先を設定
  497.             $this->setLoginTargetPath($this->generateUrl('product_add_favorite', ['id' => $Product->getId()], UrlGeneratorInterface::ABSOLUTE_URL));
  498.             $this->session->getFlashBag()->set('eccube.add.favorite'true);
  499.             $event = new EventArgs(
  500.                 [
  501.                     'Product' => $Product,
  502.                 ],
  503.                 $request
  504.             );
  505.             $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE$event);
  506.             return $this->redirectToRoute('mypage_login');
  507.         }
  508.     }
  509.     /**
  510.      * カートに追加.
  511.      *
  512.      * @Route("/products/add_cart/{id}", name="product_add_cart", methods={"POST"}, requirements={"id" = "\d+"})
  513.      */
  514.     public function addCart(Request $requestProduct $Product)
  515.     {
  516.         // エラーメッセージの配列
  517.         $errorMessages = [];
  518.         if (!$this->checkVisibility($Product)) {
  519.             throw new NotFoundHttpException();
  520.         }
  521.         $builder $this->formFactory->createNamedBuilder(
  522.             '',
  523.             AddCartType::class,
  524.             null,
  525.             [
  526.                 'product' => $Product,
  527.                 'id_add_product_id' => false,
  528.             ]
  529.         );
  530.         $event = new EventArgs(
  531.             [
  532.                 'builder' => $builder,
  533.                 'Product' => $Product,
  534.             ],
  535.             $request
  536.         );
  537.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_CART_ADD_INITIALIZE$event);
  538.         /* @var $form \Symfony\Component\Form\FormInterface */
  539.         $form $builder->getForm();
  540.         $form->handleRequest($request);
  541.         if (!$form->isValid()) {
  542.             throw new NotFoundHttpException();
  543.         }
  544.         $addCartData $form->getData();
  545.         log_info(
  546.             'カート追加処理開始',
  547.             [
  548.                 'product_id' => $Product->getId(),
  549.                 'product_class_id' => $addCartData['product_class_id'],
  550.                 'quantity' => $addCartData['quantity'],
  551.             ]
  552.         );
  553.         // カートへ追加
  554.         $this->cartService->addProduct($addCartData['product_class_id'], $addCartData['quantity']);
  555.         // 明細の正規化
  556.         $Carts $this->cartService->getCarts();
  557.         foreach ($Carts as $Cart) {
  558.             $result $this->purchaseFlow->validate($Cart, new PurchaseContext($Cart$this->getUser()));
  559.             // 復旧不可のエラーが発生した場合は追加した明細を削除.
  560.             if ($result->hasError()) {
  561.                 $this->cartService->removeProduct($addCartData['product_class_id']);
  562.                 foreach ($result->getErrors() as $error) {
  563.                     $errorMessages[] = $error->getMessage();
  564.                 }
  565.             }
  566.             foreach ($result->getWarning() as $warning) {
  567.                 $errorMessages[] = $warning->getMessage();
  568.             }
  569.         }
  570.         $this->cartService->save();
  571.         log_info(
  572.             'カート追加処理完了',
  573.             [
  574.                 'product_id' => $Product->getId(),
  575.                 'product_class_id' => $addCartData['product_class_id'],
  576.                 'quantity' => $addCartData['quantity'],
  577.             ]
  578.         );
  579.         $event = new EventArgs(
  580.             [
  581.                 'form' => $form,
  582.                 'Product' => $Product,
  583.             ],
  584.             $request
  585.         );
  586.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_CART_ADD_COMPLETE$event);
  587.         if ($event->getResponse() !== null) {
  588.             return $event->getResponse();
  589.         }
  590.         if ($request->isXmlHttpRequest()) {
  591.             // ajaxでのリクエストの場合は結果をjson形式で返す。
  592.             // 初期化
  593.             $done null;
  594.             $messages = [];
  595.             if (empty($errorMessages)) {
  596.                 // エラーが発生していない場合
  597.                 $done true;
  598.                 array_push($messagestrans('front.product.add_cart_complete'));
  599.             } else {
  600.                 // エラーが発生している場合
  601.                 $done false;
  602.                 $messages $errorMessages;
  603.             }
  604.             return $this->json(['done' => $done'messages' => $messages]);
  605.         } else {
  606.             // ajax以外でのリクエストの場合はカート画面へリダイレクト
  607.             foreach ($errorMessages as $errorMessage) {
  608.                 $this->addRequestError($errorMessage);
  609.             }
  610.             return $this->redirectToRoute('cart');
  611.         }
  612.     }
  613.     /**
  614.      * ページタイトルの設定
  615.      *
  616.      * @param  array|null $searchData
  617.      *
  618.      * @return str
  619.      */
  620.     protected function getPageTitle($searchData)
  621.     {
  622.         if (isset($searchData['name']) && !empty($searchData['name'])) {
  623.             return trans('front.product.search_result');
  624.         } elseif (isset($searchData['category_id']) && $searchData['category_id']) {
  625.             return $searchData['category_id']->getName();
  626.         } else {
  627.             return trans('front.product.all_products');
  628.         }
  629.     }
  630.     /**
  631.      * 閲覧可能な商品かどうかを判定
  632.      *
  633.      * @param Product $Product
  634.      *
  635.      * @return boolean 閲覧可能な場合はtrue
  636.      */
  637.     protected function checkVisibility(Product $Product)
  638.     {
  639.         $is_admin $this->session->has('_security_admin');
  640.         // 管理ユーザの場合はステータスやオプションにかかわらず閲覧可能.
  641.         if (!$is_admin) {
  642.             // 在庫なし商品の非表示オプションが有効な場合.
  643.             // if ($this->BaseInfo->isOptionNostockHidden()) {
  644.             //     if (!$Product->getStockFind()) {
  645.             //         return false;
  646.             //     }
  647.             // }
  648.             // 公開ステータスでない商品は表示しない.
  649.             if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
  650.                 return false;
  651.             }
  652.         }
  653.         return true;
  654.     }
  655. }