You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Shopware触发checkout.customer.double_opt_in_registration而非register事件

解决Shopware触发checkout.customer.double_opt_in_registration事件的问题
  • 直接调用customerRepository->create无法触发目标事件
    Shopware的checkout.customer.double_opt_in_registration事件并非由Repository的CRUD操作触发,而是由CustomerRegistrationService中的业务逻辑负责分发。customerRepository仅做数据持久化,不处理双选注册的业务流程(比如发送确认邮件、触发事件)。

  • 正确做法:使用CustomerRegistrationService完成注册
    你需要注入CustomerRegistrationInterface(对应实现类CustomerRegistrationService),调用其register方法来完成注册,而非直接操作Repository。示例代码如下:

    // 在类的构造函数中注入服务
    private CustomerRegistrationInterface $customerRegistrationService;
    
    public function __construct(CustomerRegistrationInterface $customerRegistrationService)
    {
        $this->customerRegistrationService = $customerRegistrationService;
    }
    
    // 执行注册逻辑
    $customer = $this->customerRegistrationService->register(
        $someArrayData,
        $context,
        true // 传入true明确启用双选注册流程
    );
    
  • 参数与配置验证

    • 确保$someArrayData包含客户注册所需的必填字段(如email、password、firstName等);
    • 后台"注册时启用双选确认"的全局设置是生效的,但通过register方法的第三个参数可以单独控制当前注册是否走双选流程。
  • 为什么之前的参数组合无效?
    你设置的doubleOptInRegistration、active等字段只是客户实体的属性值,仅设置这些属性不会触发事件——事件触发是双选注册业务流程的一环,必须由Service层来完成事件分发、邮件发送等操作。

内容的提问来源于stack exchange,提问作者Ifnir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 05:52:38