app/Plugin/PiaEvent/Event.php line 85

Open in your IDE?
  1. <?php
  2. /**
  3.  * 共通で使うカテゴリーなどを各ページに設定
  4.  */
  5. namespace Plugin\PiaEvent;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Eccube\Event\TemplateEvent;
  8. use Eccube\Repository\CategoryRepository;
  9. use Eccube\Repository\ProductRepository;
  10. use Plugin\ProductPlus42\Repository\ProductItemOptionRepository;
  11. use Plugin\CustomerRank42\Repository\CustomerPriceRepository;
  12. use Plugin\ProductPlus42\Repository\ProductDataDetailRepository;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. /**
  15.  * Class Event.
  16.  */
  17. class Event implements EventSubscriberInterface {
  18.   /**
  19.    * @var EntityManagerInterface
  20.    */
  21.   private $entityManager;
  22.   /**
  23.    * @var CategoryRepository
  24.    */
  25.   protected $categoryRepository;
  26.   protected $ProductRepository;
  27.   protected $ProductItemOptionRepository;
  28.   protected $CustomerPriceRepository;
  29.   
  30.   protected $ProductDataDetailRepository;
  31.   /**
  32.    * @var \Twig\Environment
  33.    */
  34.   private $twig;
  35.   /**
  36.    * Event constructor.
  37.    *
  38.    * @param EntityManagerInterface $entityManager
  39.    * @param \Twig\Environment $twig
  40.    */
  41.   public function __construct(
  42.     EntityManagerInterface $entityManager
  43.     CategoryRepository $categoryRepository,
  44.     ProductRepository $ProductRepository,
  45.     ProductItemOptionRepository $ProductItemOptionRepository,
  46.     CustomerPriceRepository $CustomerPriceRepository,
  47.     ProductDataDetailRepository $ProductDataDetailRepository,
  48.     \Twig\Environment $twig) {
  49.     $this->entityManager $entityManager;
  50.     $this->categoryRepository $categoryRepository;
  51.     $this->ProductRepository $ProductRepository;
  52.     $this->ProductItemOptionRepository $ProductItemOptionRepository;
  53.     $this->CustomerPriceRepository $CustomerPriceRepository;
  54.     $this->ProductDataDetailRepository $ProductDataDetailRepository;
  55.     $this->twig $twig;
  56.   }
  57.   /**
  58.    * Todo: admin.order.delete.complete has been deleted.
  59.    *
  60.    * @return array
  61.    */
  62.   public static function getSubscribedEvents() {
  63.     return [
  64.       'Product/list.twig' => 'onProductListRender',
  65.     ];
  66.   }
  67.   /**
  68.    * 絞込み検索結果を商品一覧ページに設定
  69.    * @param TemplateEvent $event
  70.    */
  71.   public function onProductListRender(TemplateEvent $event) {
  72.     $htGrade $this->ProductItemOptionRepository->getHash("3");
  73.     unset($htGrade["79"]);
  74.     $parameters $event->getParameters();
  75.     $parameters["htPrice"] = $this->getHashPrice();
  76.     $parameters["htMaterial"] = $this->categoryRepository->getHash("93"); // 素材
  77.     $parameters["htCountry"] = $this->categoryRepository->getHash("10");  // 国
  78.     $parameters["htYear"] = $this->categoryRepository->getHash("167");    // 発行年
  79.     $parameters["htWeight"] = $this->ProductItemOptionRepository->getHash("56");  // 重量
  80.     $parameters["htGrade"] = $htGrade;    // グレード
  81.     $parameters["htCategory"] = $this->categoryRepository->getHash("1");  // カテゴリー
  82.     $parameters["htRare"] = $this->categoryRepository->getHash("102");    // レア
  83.     $parameters["htNum"] = $this->getHashNum();
  84.     $parameters["params"] = $this->_getParams();
  85.     
  86.     $parameters["htCPrice"] = $this->CustomerPriceRepository->getHashPrice(); // 会員価格
  87.     $parameters["htStatus"] = $this->ProductRepository->getHashStatus();      // 商品ステータス
  88.     $parameters["htMeyasu"] = $this->ProductDataDetailRepository->getHash("55"); // 
  89.     
  90.     $parameters["htPageNum"] = $this->getHashPageNum(); // ページの商品数
  91.     $parameters["htOrderBy"] = $this->getHashOrderBy(); // 表示順
  92.     // 地金の商品一覧を取得
  93.     $parameters["htJigane"] = $this->categoryRepository->getHashCategory("5");
  94.     $event->setParameters($parameters);
  95.   }
  96.   /**
  97.    * チェックした項目を反映
  98.    * @return hash
  99.    */
  100.   private function _getParams(){
  101.     $hash = array();
  102.     $hash["search_price"] = array();
  103.     $hash["search_material"] = array();
  104.     $hash["search_country"] = array();
  105.     $hash["search_year"] = array();
  106.     $hash["search_weight"] = array();
  107.     $hash["search_grade"] = array();
  108.     $hash["search_category"] = array();
  109.     $hash["search_rare"] = array();
  110.     $hash["search_num"] = array();
  111.     if(!empty($_GET["search_price"]) and count($_GET["search_price"]) > 0){
  112.       foreach($_GET["search_price"] as $k){
  113.         $hash["search_price"][$k] = true;
  114.       }
  115.     }
  116.     if(!empty($_GET["search_material"]) and count($_GET["search_material"]) > 0){
  117.       foreach($_GET["search_material"] as $k){
  118.         $hash["search_material"][$k] = true;
  119.       }
  120.     }
  121.     if(!empty($_GET["search_country"]) and count($_GET["search_country"]) > 0){
  122.       foreach($_GET["search_country"] as $k){
  123.         $hash["search_country"][$k] = true;
  124.       }
  125.     }
  126.     if(!empty($_GET["search_year"]) and count($_GET["search_year"]) > 0){
  127.       foreach($_GET["search_year"] as $k){
  128.         $hash["search_year"][$k] = true;
  129.       }
  130.     }
  131.     if(!empty($_GET["search_weight"]) and count($_GET["search_weight"]) > 0){
  132.       foreach($_GET["search_weight"] as $k){
  133.         $hash["search_weight"][$k] = true;
  134.       }
  135.     }
  136.     if(!empty($_GET["search_grade"]) and count($_GET["search_grade"]) > 0){
  137.       foreach($_GET["search_grade"] as $k){
  138.         $hash["search_grade"][$k] = true;
  139.       }
  140.     }
  141.     if(!empty($_GET["search_category"]) and count($_GET["search_category"]) > 0){
  142.       foreach($_GET["search_category"] as $k){
  143.         $hash["search_category"][$k] = true;
  144.       }
  145.     }
  146.     if(!empty($_GET["search_rare"]) and count($_GET["search_rare"]) > 0){
  147.       foreach($_GET["search_rare"] as $k){
  148.         $hash["search_rare"][$k] = true;
  149.       }
  150.     }
  151.     if(!empty($_GET["search_num"]) and count($_GET["search_num"]) > 0){
  152.       foreach($_GET["search_num"] as $k){
  153.         $hash["search_num"][$k] = true;
  154.       }
  155.     }
  156.     $hash["disp_number"] = false;
  157.     if(!empty($_GET["disp_number"])){
  158.       $hash["disp_number"] = $_GET["disp_number"];
  159.     }
  160.     $hash["orderby"] = false;
  161.     if(!empty($_GET["orderby"])){
  162.       $hash["orderby"] = $_GET["orderby"];
  163.     }
  164.     $hash["stock_flg_chk"] = false;
  165.     if(!empty($_GET["stock_flg_chk"])){
  166.       $hash["stock_flg_chk"] = true;
  167.     }
  168.     return $hash;
  169.   }
  170.   /**
  171.    * 検索価格一覧をハッシュで取得
  172.    * @return hash
  173.    */
  174.   public function getHashPrice(){
  175.     $hash = array(
  176.       '1' => '~50万円未満',
  177.       '2' => '50~100万円未満',
  178.       '3' => '100~300万円未満',
  179.       '4' => '300~500万円未満',
  180.       '5' => '500~1,000万円未満',
  181.       '6' => '1,000万円台',
  182.       '7' => '2,000万円台',
  183.       '8' => '3,000万円台',
  184.       '9' => '4,000万円台',
  185.       '10' => '5,000~1億円未満',
  186.       '11' => '1億円以上',
  187.     );
  188.     return $hash;
  189.   }
  190.   /**
  191.    * 発行枚数をハッシュで取得
  192.    * @return hash
  193.    */
  194.   public function getHashNum(){
  195.     $hash = array(
  196.       '1' => '1枚',
  197.       '2' => '2~5枚',
  198.       '3' => '6~10枚',
  199.       '4' => '11~20枚',
  200.       '5' => '21~30枚',
  201.       '6' => '31~40枚',
  202.       '7' => '41~50枚',
  203.       '8' => '51~100枚',
  204.       '9' => '101~500枚',
  205.       '10' => '501~1,000枚',
  206.       '11' => '1,001~5,000枚',
  207.       '12' => '5,001~10,000枚',
  208.     );
  209.     return $hash;
  210.   }
  211.   
  212.   /**
  213.    * 商品一覧に表示する件数をハッシュで取得
  214.    * @return hash
  215.    */
  216.   public function getHashPageNum(){
  217.     $hash = array(
  218.       '30' => '30件',
  219.       '50' => '50件',
  220.       '100' => '100件',
  221.     );
  222.     return $hash;
  223.   }
  224.   
  225.   /**
  226.    * 商品一覧の表示順をハッシュで取得
  227.    * @return hash
  228.    */
  229.   public function getHashOrderBy(){
  230.     $hash = array(
  231.       '2' => '新着順',
  232.       '1' => '価格が低い順',
  233.       '3' => '価格が高い順',
  234.     );
  235.     return $hash;
  236.   }
  237.   
  238. }