<?php
/*
* Plugin Name : PointExpired
*
* 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\PointExpired42\Event;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Plugin\PointExpired42\Repository\ConfigRepository;
use Plugin\PointExpired42\Service\PointExpiredService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FrontEvent implements EventSubscriberInterface
{
private $entityManager;
private $configRepository;
public function __construct(
EntityManagerInterface $entityManager,
ConfigRepository $configRepository
)
{
$this->entityManager = $entityManager;
$this->configRepository = $configRepository;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE => 'hookFrontEntryIndexComplete',
];
}
public function hookFrontEntryIndexComplete(EventArgs $event)
{
$Customer = $event->getArgument('Customer');
$config = $this->configRepository->findOneBy(['name' => 'period']);
if($config){
$period = $config->getValue();
$Customer->setExtensionPeriod($period);
$this->entityManager->persist($Customer);
$this->entityManager->flush($Customer);
}
}
}