如何像Shopware 5一样在Shopware 6中订阅预发布的注册?

如何像Shopware 5一样在Shopware 6中订阅预发布的注册?,shopware,Shopware,我想在注册过程开始之前调用一个函数,以便检查注册表中的一些值。在Shopware 5中,我将使用预剥离事件。如何在Shopware 6中实现这一点 这是表单将注册数据发布到以下位置的方法: /** * @Route("/account/register", name="frontend.account.register.save", methods={"POST"}) * @Captcha */ public function r

我想在注册过程开始之前调用一个函数,以便检查注册表中的一些值。在Shopware 5中,我将使用预剥离事件。如何在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类。 映射\注册\客户应该是您正在寻找的客户

<?php

namespace Vendor\Plugin\Subscriber;

use Shopware\Core\Checkout\Customer\CustomerEvents;
use Shopware\Core\Framework\Event\DataMappingEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

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;
    }
}

我认为您可以订阅它的最早事件是
framework.validation.customer.create
。 它在注册表项下调度::getCustomerCreateValidationDefinition()
。在subscriber中,可以扩展验证约束。 如果您需要提前做一些事情,我认为最好的解决方案是重写/修饰
RegisterRoute


您可以在那里查看我的答案,这可能也会有所帮助。

我认为事件是CustomerEvents::CUSTOMER\u REGISTER\u event是在注册过程开始之前调用的映射\u REGISTER\u CUSTOMER吗?它是否像sw5的predispatch或postdispatchsecure?“framework.validation.customer.address.number.validation.update'=>“onRegister”是可以使用函数订阅的事件名称?验证约束是如何扩展的?是否有任何参考或文档?很抱歉,我复制了错误的事件,只是编辑了它。正确的方法是
framework.validation.customer.create
之后,您可以像这样定义订阅服务器方法:
onRegister(BuildValidationEvent$event){$definition=$event->getDefinition();$definition->add('someField',new NotBlank();}
    <!-- Event Subscribers -->
    <service id="Vendor\Plugin\Subscriber\RegisterSubscriber">
        <tag name="kernel.event_subscriber"/>
    </service>