app/Plugin/CheckProduct4/Controller/Block/CheckProductController.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright(c) 2019 SYSTEM FRIEND INC.
  4.  */
  5. namespace Plugin\CheckProduct4\Controller\Block;
  6. use Eccube\Controller\AbstractController;
  7. use Eccube\Entity\Master\ProductStatus;
  8. use Eccube\Repository\ProductRepository;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\HttpFoundation\Request;
  14. class CheckProductController extends AbstractController
  15. {
  16.     /**
  17.      * @var RequestStack
  18.      */
  19.     protected $session;
  20.     /**
  21.      * @var ProductRepository
  22.      */
  23.     protected $productRepository;
  24.     public function __construct(SessionInterface $session,ProductRepository $productRepository) {
  25.         $this->session $session;
  26.         $this->productRepository $productRepository;
  27.     }
  28.     /**
  29.      * @Route("/block/check_product", name="block_check_product")
  30.      * @Template("Block/check_product.twig")
  31.      *
  32.      * @param Request $request
  33.      * @return array
  34.      */
  35.     public function index(Request $request) {
  36.         $productId =  $this->session->get('plugin.check_product.product') ?: array();
  37.         $CheckProducts = array();
  38.         foreach ($productId as $id) {
  39.             $Product $this->productRepository->find($id);
  40.             if(!is_null($Product) && $Product->getStatus()->getId() === ProductStatus::DISPLAY_SHOW) {
  41.                 $CheckProducts[] = $Product;
  42.             }
  43.         }
  44.         return [
  45.             'CheckProducts' => $CheckProducts,
  46.         ];
  47.     }
  48. }