<?php
/**
* Copyright(c) 2022 SYSTEM_KD
* Date: 2022/11/26
*/
namespace Plugin\OrderStatusEx\EventSubscriber;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Plugin\OrderStatusEx\Entity\OrderStatusEvent;
use Plugin\OrderStatusEx\Repository\OrderStatusEventRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class SearchEventSubscriber implements EventSubscriberInterface
{
/** @var OrderStatusEventRepository */
protected $orderStatusEventRepository;
public function __construct(
OrderStatusEventRepository $orderStatusEventRepository
)
{
$this->orderStatusEventRepository = $orderStatusEventRepository;
}
public function onAdminAdminIndexOrder(EventArgs $event)
{
$excludes = $event->getArgument('excludes');
$status = [
OrderStatusEvent::EVENT_GROUP_CANCEL,
OrderStatusEvent::EVENT_GROUP_RETURN,
OrderStatusEvent::EVENT_GROUP_DELIVERY,
];
$orderStatusExEvents = $this->orderStatusEventRepository->findOrderStatusEvents($status);
/** @var OrderStatusEvent $orderStatusExEvent */
foreach ($orderStatusExEvents as $orderStatusExEvent) {
$targetOrderStatusId = $orderStatusExEvent->getOrderStatusId();
$excludes[] = $targetOrderStatusId;
}
$event->setArgument('excludes', $excludes);
}
public function onAdminAdminIndexSales(EventArgs $event)
{
$excludes = $event->getArgument('excludes');
// 取消・返品相当のステータス追加
$orderStatusExEvents = $this->orderStatusEventRepository->getNoOrderStatusEvents();
/** @var OrderStatusEvent $orderStatusExEvent */
foreach ($orderStatusExEvents as $orderStatusExEvent) {
$targetOrderStatusId = $orderStatusExEvent->getOrderStatusId();
$excludes[] = $targetOrderStatusId;
}
$event->setArgument('excludes', $excludes);
}
public static function getSubscribedEvents()
{
return [
// ホーム 件数一覧
EccubeEvents::ADMIN_ADMIM_INDEX_ORDER => 'onAdminAdminIndexOrder',
// ホーム 売上状況
EccubeEvents::ADMIN_ADMIM_INDEX_SALES => 'onAdminAdminIndexSales',
];
}
}