<?php
/**
* 共通で使うカテゴリーなどを各ページに設定
*/
namespace Plugin\PiaEvent;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Event\TemplateEvent;
use Eccube\Repository\CategoryRepository;
use Eccube\Repository\ProductRepository;
use Plugin\ProductPlus42\Repository\ProductItemOptionRepository;
use Plugin\CustomerRank42\Repository\CustomerPriceRepository;
use Plugin\ProductPlus42\Repository\ProductDataDetailRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class Event.
*/
class Event implements EventSubscriberInterface {
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var CategoryRepository
*/
protected $categoryRepository;
protected $ProductRepository;
protected $ProductItemOptionRepository;
protected $CustomerPriceRepository;
protected $ProductDataDetailRepository;
/**
* @var \Twig\Environment
*/
private $twig;
/**
* Event constructor.
*
* @param EntityManagerInterface $entityManager
* @param \Twig\Environment $twig
*/
public function __construct(
EntityManagerInterface $entityManager,
CategoryRepository $categoryRepository,
ProductRepository $ProductRepository,
ProductItemOptionRepository $ProductItemOptionRepository,
CustomerPriceRepository $CustomerPriceRepository,
ProductDataDetailRepository $ProductDataDetailRepository,
\Twig\Environment $twig) {
$this->entityManager = $entityManager;
$this->categoryRepository = $categoryRepository;
$this->ProductRepository = $ProductRepository;
$this->ProductItemOptionRepository = $ProductItemOptionRepository;
$this->CustomerPriceRepository = $CustomerPriceRepository;
$this->ProductDataDetailRepository = $ProductDataDetailRepository;
$this->twig = $twig;
}
/**
* Todo: admin.order.delete.complete has been deleted.
*
* @return array
*/
public static function getSubscribedEvents() {
return [
'Product/list.twig' => 'onProductListRender',
];
}
/**
* 絞込み検索結果を商品一覧ページに設定
* @param TemplateEvent $event
*/
public function onProductListRender(TemplateEvent $event) {
$htGrade = $this->ProductItemOptionRepository->getHash("3");
unset($htGrade["79"]);
$parameters = $event->getParameters();
$parameters["htPrice"] = $this->getHashPrice();
$parameters["htMaterial"] = $this->categoryRepository->getHash("93"); // 素材
$parameters["htCountry"] = $this->categoryRepository->getHash("10"); // 国
$parameters["htYear"] = $this->categoryRepository->getHash("167"); // 発行年
$parameters["htWeight"] = $this->ProductItemOptionRepository->getHash("56"); // 重量
$parameters["htGrade"] = $htGrade; // グレード
$parameters["htCategory"] = $this->categoryRepository->getHash("1"); // カテゴリー
$parameters["htRare"] = $this->categoryRepository->getHash("102"); // レア
$parameters["htNum"] = $this->getHashNum();
$parameters["params"] = $this->_getParams();
$parameters["htCPrice"] = $this->CustomerPriceRepository->getHashPrice(); // 会員価格
$parameters["htStatus"] = $this->ProductRepository->getHashStatus(); // 商品ステータス
$parameters["htMeyasu"] = $this->ProductDataDetailRepository->getHash("55"); //
$parameters["htPageNum"] = $this->getHashPageNum(); // ページの商品数
$parameters["htOrderBy"] = $this->getHashOrderBy(); // 表示順
// 地金の商品一覧を取得
$parameters["htJigane"] = $this->categoryRepository->getHashCategory("5");
$event->setParameters($parameters);
}
/**
* チェックした項目を反映
* @return hash
*/
private function _getParams(){
$hash = array();
$hash["search_price"] = array();
$hash["search_material"] = array();
$hash["search_country"] = array();
$hash["search_year"] = array();
$hash["search_weight"] = array();
$hash["search_grade"] = array();
$hash["search_category"] = array();
$hash["search_rare"] = array();
$hash["search_num"] = array();
if(!empty($_GET["search_price"]) and count($_GET["search_price"]) > 0){
foreach($_GET["search_price"] as $k){
$hash["search_price"][$k] = true;
}
}
if(!empty($_GET["search_material"]) and count($_GET["search_material"]) > 0){
foreach($_GET["search_material"] as $k){
$hash["search_material"][$k] = true;
}
}
if(!empty($_GET["search_country"]) and count($_GET["search_country"]) > 0){
foreach($_GET["search_country"] as $k){
$hash["search_country"][$k] = true;
}
}
if(!empty($_GET["search_year"]) and count($_GET["search_year"]) > 0){
foreach($_GET["search_year"] as $k){
$hash["search_year"][$k] = true;
}
}
if(!empty($_GET["search_weight"]) and count($_GET["search_weight"]) > 0){
foreach($_GET["search_weight"] as $k){
$hash["search_weight"][$k] = true;
}
}
if(!empty($_GET["search_grade"]) and count($_GET["search_grade"]) > 0){
foreach($_GET["search_grade"] as $k){
$hash["search_grade"][$k] = true;
}
}
if(!empty($_GET["search_category"]) and count($_GET["search_category"]) > 0){
foreach($_GET["search_category"] as $k){
$hash["search_category"][$k] = true;
}
}
if(!empty($_GET["search_rare"]) and count($_GET["search_rare"]) > 0){
foreach($_GET["search_rare"] as $k){
$hash["search_rare"][$k] = true;
}
}
if(!empty($_GET["search_num"]) and count($_GET["search_num"]) > 0){
foreach($_GET["search_num"] as $k){
$hash["search_num"][$k] = true;
}
}
$hash["disp_number"] = false;
if(!empty($_GET["disp_number"])){
$hash["disp_number"] = $_GET["disp_number"];
}
$hash["orderby"] = false;
if(!empty($_GET["orderby"])){
$hash["orderby"] = $_GET["orderby"];
}
$hash["stock_flg_chk"] = false;
if(!empty($_GET["stock_flg_chk"])){
$hash["stock_flg_chk"] = true;
}
return $hash;
}
/**
* 検索価格一覧をハッシュで取得
* @return hash
*/
public function getHashPrice(){
$hash = array(
'1' => '~50万円未満',
'2' => '50~100万円未満',
'3' => '100~300万円未満',
'4' => '300~500万円未満',
'5' => '500~1,000万円未満',
'6' => '1,000万円台',
'7' => '2,000万円台',
'8' => '3,000万円台',
'9' => '4,000万円台',
'10' => '5,000~1億円未満',
'11' => '1億円以上',
);
return $hash;
}
/**
* 発行枚数をハッシュで取得
* @return hash
*/
public function getHashNum(){
$hash = array(
'1' => '1枚',
'2' => '2~5枚',
'3' => '6~10枚',
'4' => '11~20枚',
'5' => '21~30枚',
'6' => '31~40枚',
'7' => '41~50枚',
'8' => '51~100枚',
'9' => '101~500枚',
'10' => '501~1,000枚',
'11' => '1,001~5,000枚',
'12' => '5,001~10,000枚',
);
return $hash;
}
/**
* 商品一覧に表示する件数をハッシュで取得
* @return hash
*/
public function getHashPageNum(){
$hash = array(
'30' => '30件',
'50' => '50件',
'100' => '100件',
);
return $hash;
}
/**
* 商品一覧の表示順をハッシュで取得
* @return hash
*/
public function getHashOrderBy(){
$hash = array(
'2' => '新着順',
'1' => '価格が低い順',
'3' => '価格が高い順',
);
return $hash;
}
}