Shopware:为客户存储自定义字段
我将此自定义字段添加到我的客户和注册表中storefront/component/account/register.html.twig:
<input type="checkbox" name="custom_kw_dau" value="1">
该字段是类型复选框。它在后端工作正常,但在客户注册期间未填写。
回答
您必须手动存储它。订阅事件并将字段添加到customFields输出中,如下所示:
public static function getSubscribedEvents(): array
{
return [
CustomerEvents::MAPPING_REGISTER_CUSTOMER => 'addCustomField'
];
}
public function addCustomField(DataMappingEvent $event): bool
{
$inputData = $event->getInput();
$outputData = $event->getOutput();
$custom_field = (bool)$inputData->get('custom_kw_dau', false);
$outputData['customFields'] = array('custom_kw_dau' => $custom_field);
$event->setOutput($outputData);
return true;
}