<?php
/*
* Plugin Name : CustomerRank
*
* Copyright (C) BraTech Co., Ltd. All Rights Reserved.
* http://www.bratech.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\CustomerRank42\Event;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Plugin\CustomerRank42\Repository\CustomerRankRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class EntryEvent implements EventSubscriberInterface
{
private $entityManager;
private $customerRankRepository;
/**
* CustomerRankController constructor.
* @param CustomerRankRepository $customerRankRepository
*/
public function __construct(
EntityManagerInterface $entityManager,
CustomerRankRepository $customerRankRepository
)
{
$this->entityManager = $entityManager;
$this->customerRankRepository = $customerRankRepository;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE => 'hookFrontEntryIndexComplete',
];
}
public function hookFrontEntryIndexComplete(EventArgs $event)
{
$Customer = $event->getArgument('Customer');
$CustomerRank = $this->customerRankRepository->findOneBy(['initial_flg' => true]);
if(!is_null($CustomerRank)){
$Customer->setCustomerRank($CustomerRank);
$this->entityManager->persist($Customer);
$this->entityManager->flush($Customer);
}
}
}