<?php
namespace Plugin\MyufullConnect\EventListener\admin\Order;
use Eccube\Event\TemplateEvent;
use Eccube\Repository\CustomerRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class Edit implements EventSubscriberInterface
{
/**
* @var CustomerRepository
*/
protected $customerRepository;
/**
* constructor.
*
*/
public function __construct(
CustomerRepository $customerRepository
)
{
$this->customerRepository = $customerRepository;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'@admin/Order/edit.twig' => 'edit',
];
}
/**
* 管理画面の受注登録(新規・変更)時に呼び出される
* @param TemplateEvent $event
*/
public function edit(TemplateEvent $event)
{
$order = $event->getParameter('Order');
$customer = $order->getCustomer();
if ($customer) {
// 受注が会員と紐付いている場合(非会員でないとき)
$code = $customer->myuseAgencyCode();
$event->setParameter('myuseAgencyCode', $code);
// 受注の「注文者」欄の最後に紹介者IDを表示
$event->addSnippet('@MyufullConnect/admin/Order/edit.twig');
}
}
}