Pav*_*vel 3 plugins e-commerce shopware
我需要编写一个 Shopware 插件,用external_id字段扩展客户模型。该字段应该可以通过管理 UI 和 API 进行编辑。
我发现我可以向用户添加属性,如下所示:
public function addAttributes() {
$this->Application()->Models()->addAttribute(
's_user_attributes',
'bla',
'externalId',
'INT(11)',
true,
null
);
$this->Application()->Models()->generateAttributeModels(array(
's_user_attributes'
));
}
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能在 UI 和 API 中显示此字段?
PS:商店软件5
addAttribute在 Shopware 5 中已弃用。请改为shopware_attribute.crud_service从Shopware()-container 中使用。
$service = Shopware()->Container()->get('shopware_attribute.crud_service');
$service->update('s_user_attributes', 'bla', 'integer', [
'label' => '',
'supportText' => '',
'helpText' => '',
'translatable' => false,
'displayInBackend' => true,
'position' => 1
]);
Shopware()->Models()->generateAttributeModels(
array(
's_user_attributes'
)
);
Run Code Online (Sandbox Code Playgroud)
如果设置displayInBackend为true,则可以在用户所在的后端进行编辑。
更多内容请参见Shopware 开发人员指南。