正如标题所说,我想扩展一个电子邮件实体,所以我正在尝试订阅MAPPING_REGISTER_CUSTOMER事件。当用户提交表单时,我想扩展传出的电子邮件。目前正在处理这个例外
这是一个例外:
Argument 1 passed to RegistrationExtensionSubscriberRegisterExtensionSubscriber::onCustomRegister() must be an instance of ShopwareCoreFrameworkDataAbstractionLayerEventEntityLoadedEvent, instance of ShopwareCoreFrameworkEventDataMappingEvent given, called in /app/vendor/symfony/event-dispatcher/Debug/WrappedListener.php on line 126
这里是我的代码:(
<?php
namespace RegistrationExtensionSubscriber;
use ShopwareCoreFrameworkDataAbstractionLayerEventEntityLoadedEvent;
use SymfonyComponentEventDispatcherEventSubscriberInterface;
use ShopwareCoreCheckoutCustomerCustomerEvents;
use ShopwareCoreCheckoutCustomerCustomerEntity;
use ShopwareCoreSystemSalesChannelSalesChannelContext;
use ShopwareStorefrontControllerStorefrontController;
use ShopwareCoreFrameworkDataAbstractionLayerSearchCriteria;
use ShopwareCoreFrameworkDataAbstractionLayerSearchFilterEqualsFilter;
use ShopwareCoreFrameworkDataAbstractionLayerEntityRepositoryInterface;
class RegisterExtensionSubscriber implements EventSubscriberInterface{
public static function getSubscribedEvents(): array{
return [
CustomerEvents::MAPPING_REGISTER_CUSTOMER => 'onCustomRegister'
];
}
public function onCustomRegister(EntityLoadedEvent $event , SalesChannelContext $context){
/**
* @var EntityRepositoryInterface $mailTypeRepository
* @var EntityRepositoryInterface $mailRepository
*/
$mailTypeRepository = $this->container->get('mail_template_type.repository');
$mailRepository = $this->container->get('mail_template.repository');
$mailEntity = $mailTypeRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template_type.technicalName', "customer_register")),
$context->getContext()
);
$mailTypeId = $mailEntity->getEntities()->first()->getId();
$mailEntity = $mailRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template.mailTemplateTypeId', $mailTypeId)),
$context->getContext()
);
//$mailEntity->getEntities()->setContentHtml("test");
$mail = $mailEntity->getEntities();
return $this->renderStorefront(
'@Storefront/storefront/page/checkout/address/index.html.twig',[
'page' => $context,
'mailEntity' => $mail
]
);
/** @var CustomerEntity $customerRegisEvent */
foreach ($event->getEntities() as $customerRegisEvent) {
$customerRegisEvent->addExtension('custom_struct', new RegisterStruct());
}
}
}
任何帮助都是值得的:(
[EDIT]
<?php
namespace RegistrationExtensionSubscriber;
use ShopwareCoreFrameworkDataAbstractionLayerEventEntityLoadedEvent;
use SymfonyComponentEventDispatcherEventSubscriberInterface;
use ShopwareCoreCheckoutCustomerCustomerEvents;
use ShopwareCoreCheckoutCustomerCustomerEntity;
use ShopwareCoreSystemSalesChannelSalesChannelContext;
use ShopwareStorefrontControllerStorefrontController;
use ShopwareCoreFrameworkDataAbstractionLayerSearchCriteria;
use ShopwareCoreFrameworkDataAbstractionLayerSearchFilterEqualsFilter;
use ShopwareCoreFrameworkDataAbstractionLayerEntityRepositoryInterface;
use ShopwareCoreCheckoutCustomerEventCustomerRegisterEvent;
class RegisterExtensionSubscriber implements EventSubscriberInterface{
public static function getSubscribedEvents(): array{
return [
ShopwareCoreCheckoutCustomerEventCustomerRegisterEvent::class => 'onCustomRegister'
];
}
public function onCustomRegister(ShopwareCoreCheckoutCustomerEventCustomerRegisterEvent $event){
/** @var CustomerEntity $customerRegisEvent */
foreach ($event->getMailStruct() as $customerRegisEvent) {
$customerRegisEvent->addExtension('custom_struct', new RegisterStruct());
}
}
}
您可能需要另一个事件
ShopwareCoreCheckoutCustomerEventCustomerRegisterEvent:class => 'onCustomRegister'
并且您还需要更改onCustomRegister
方法的定义
尝试
public function onCustomRegister(ShopwareCoreCheckoutCustomerEventCustomerRegisterEvent $event)
之后,您可以通过以下方式让客户了解该方法$event->getCustomer((和上下文(按$event->(;getSalesChannelContext((