简体   繁体   English

如何扩展Shopware客户

[英]How to extend Shopware customer

I need to write a Shopware plugin that extends customer model with external_id field. 我需要编写一个Shopware插件,以使用external_id字段扩展客户模型。 This field should be editable through the admin UI and API. 此字段应可通过管理界面和API进行编辑。

I've found, that I can add attribute to user like so: 我发现,可以像这样向用户添加属性:

public function addAttributes() {
    $this->Application()->Models()->addAttribute(
        's_user_attributes',
        'bla',
        'externalId',
        'INT(11)',
        true,
        null
    );

    $this->Application()->Models()->generateAttributeModels(array(
        's_user_attributes'
    ));
}

What should I do to show this field in the UI and API? 我应该怎么做才能在UI和API中显示此字段?

PS: Shopware 5 PS:Shopware 5

addAttribute is deprecated in Shopware 5. Use shopware_attribute.crud_service from the Shopware() -container instead. Shopware 5中不赞成使用addAttribute 。请shopware_attribute.crud_service Shopware() shopware_attribute.crud_service中的Shopware()

$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'
    )
);

If you set displayInBackend to true , you can edit it in the Backend, where the user is. 如果将displayInBackend设置为true ,则可以在用户所在的后端中对其进行编辑。

More at the Shopware Developer Guide . 有关更多信息,请参见《 Shopware开发人员指南》

For the backend you have to to do some ExtJs coding . 对于后端,您必须执行一些ExtJs编码

For the API you have to extend the REST-API endpoint for the user : 对于API,您必须为用户扩展REST-API端点

Shopware API erweitern Shopware API错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM