【问题标题】:Magento 2.1 Update Customer Custom EAV Attribute with REST APIMagento 2.1 使用 REST API 更新客户自定义 EAV 属性
【发布时间】:2016-10-10 07:24:39
【问题描述】:

如何使用 REST API 更新/添加客户的 EAV 属性?

我尝试使用带有此 URL 的 [PUT] /V1/customers/{id} 来做到这一点

http://<website>/rest/V1/customers/1

这是正文数据:

$data = array(
    'customer' => array(
        'id' => 1,
        'email' => 'email@domain.com', 
        'firstname' => 'John', 
        'lastname' => 'Doe', 
        'website_id' => 1,
        'custom_attributes' => array(
            'attribute_code' => 'my_custom_attribute_code',
            'value' => 'my_custom_attribute_value'
        )
    )
);

我能够编辑客户的默认属性,例如 firstnamelastname,但我无法编辑 EAV 属性。

是否可以使用默认的customerCustomerRepositoryV1 接口来做到这一点? 如果没有,您如何扩展以便可以编辑/添加客户的 EAV 属性?

谢谢。

Magento 2.1 Rest API 接口: http://devdocs.magento.com/swagger

【问题讨论】:

    标签: rest magento2


    【解决方案1】:

    正文数据有误。我忘了把索引放在custom_attributes 数组上。

    应该是这样的:

    $data = array(
        'customer' => array(
            'id' => 1,
            'email' => 'email@domain.com', 
            'firstname' => 'John', 
            'lastname' => 'Doe', 
            'website_id' => 1,
            'custom_attributes' => array(
                '0' => array(
                    'attribute_code' => 'my_custom_attribute_code',
                    'value' => 'my_custom_attribute_value'
                )
            )
        )
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 2012-11-30
      • 2015-06-25
      • 2012-07-04
      • 2018-12-26
      • 1970-01-01
      相关资源
      最近更新 更多