如何让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
相关产品推荐
相关产品推荐

