如何像商店软件5一样在商店软件6中订阅预注册

  • 本文关键字:软件 注册 何像商 一样 shopware
  • 更新时间 :
  • 英文 :


我想在注册过程开始前调用一个函数,以便检查注册表单中的一些值。在Shopware 5中,我会使用predispatch事件。如何在Shopware 6中做到这一点?

这是表格将注册数据发布到的方法:

/**
* @Route("/account/register", name="frontend.account.register.save", methods={"POST"})
* @Captcha
*/
public function register(Request $request, RequestDataBag $data, SalesChannelContext $context): Response
{

检查类Shopware\Core\Checkout\Customer\CustomerEvents。MAPPING_REGISTER_CUSTOMER应该是您要查找的。

<?php
namespace VendorPluginSubscriber;
use ShopwareCoreCheckoutCustomerCustomerEvents;
use ShopwareCoreFrameworkEventDataMappingEvent;
use SymfonyComponentEventDispatcherEventSubscriberInterface;
class RegisterSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
CustomerEvents::MAPPING_REGISTER_CUSTOMER => 'onRegister'
];
}
public function onRegister(DataMappingEvent $event)
{
$input = $event->getInput();
$output = $event->getOutput();
// do whatever you want here with the output
$event->setOutput($output);
return true;
}
}

订阅者是这样在services.xml中注册的,类似于Shopware5,只是ID是订阅者类的FQDN:

<!-- Event Subscribers -->
<service id="VendorPluginSubscriberRegisterSubscriber">
<tag name="kernel.event_subscriber"/>
</service>

我认为您可以订阅它的最早事件是framework.validation.customer.create。在RegisterRoute::getCustomerCreateValidationDefinition()调度。在订阅者中,您可以扩展验证约束。如果你需要提前做一些事情,我认为最好的解决方案是覆盖/装饰RegisterRoute

你可以在那里查看我的答案如何扩展Shopware6控制器的操作,它可能也会有所帮助。

最新更新