【发布时间】:2021-01-04 07:09:39
【问题描述】:
我有一个实体,我在登录页面上扩展,但在下一页上扩展不存在(实体在两个页面上都存在)。有没有办法让我的扩展在下一页上可用?
<?php
namespace RegistrationExtension\Subscriber;
use ...
class RegisterExtensionSubscriber implements EventSubscriberInterface{
private $company;
/**
* @var EntityRepositoryInterface
*/
private $mailTypeRepository;
/**
* @var EntityRepositoryInterface
*/
private $mailRepository;
/**
* @var EntityRepositoryInterface
*/
private $customerRepo;
public function __construct(
EntityRepositoryInterface $customerRepo,
EntityRepositoryInterface $mailTypeRepository,
EntityRepositoryInterface $mailRepository
) {
$this->customerRepo = $customerRepo;
$this->mailTypeRepository = $mailTypeRepository;
$this->mailRepository = $mailRepository;
}
public static function getSubscribedEvents(): array{
return [
AccountLoginPageLoadedEvent::class => 'extendCustomer',
AccountOverviewPageLoadedEvent::class => 'onCustomRegister'
];
}
当登录页面完成加载时触发此函数。
public function extendCustomer(AccountLoginPageLoadedEvent $event){
// if (isset($_POST['submit'])) {
if(isset($_GET["email"])){
$company = $_GET["email"];
}else{
$company = null;
}
$mailEntity = $this->mailTypeRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template_type.technicalName', "customer_register")),
$event->getContext()
);
if ($mailType = $mailEntity->getEntities()->first()) {
$mailEntity = $this->mailRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template.mailTemplateTypeId', $mailType->getId())),
$event->getContext()
);
$mailEntity->getEntities()->first()->addExtension('file_does_exist', new ArrayEntity(['company' => "blub"]));
dump($mailEntity->getEntities()->first());
}
// }
}
此函数在用户登录并且页面完成加载后触发。
public function onCustomRegister(AccountOverviewPageLoadedEvent $event){
$mailEntity = $this->mailTypeRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template_type.technicalName', "customer_register")),
$event->getContext()
);
if ($mailType = $mailEntity->getEntities()->first()) {
$mailEntity = $this->mailRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template.mailTemplateTypeId', $mailType->getId())),
$event->getContext()
);
dump($mailEntity);
// $mail = $mailEntity->getEntities()->first()->addExtension('file_does_exist', new ArrayEntity(['company' => $company]));
}
$customerEntity = $this->customerRepo->search(
(new Criteria())->addFilter(new EqualsFilter('customer.customerNumber', $event->getSalesChannelContext()->getCustomer()->getCustomerNumber())),
$event->getContext()
);
}
}
会不会是AccountOverviewPageLoadedEvent事件加载了beo?
【问题讨论】:
-
如果您有一个实体,每个登录会话只加载和扩展一次 - 为什么不使用会话来保留该实体?
-
您好,谢谢您的回复。其实就是登记表。因此,在完成注册过程之前,客户不存在。我的主要目标是客户在填写注册表时可以上传文件。在这种情况下,此文件不是扩展名。之后,我想让它在邮件实体上可用,以便每封邮件发送信息。