2016-10-10 66 views
1

如何使用REST API更新/添加客户的EAV属性?Magento 2.1使用REST API更新客户自定义EAV属性

我试图做使用[PUT] /V1/customers/{id}这个URL

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

它,并以此为主体数据:

$data = array(
    'customer' => array(
     'id' => 1, 
     'email' => '[email protected]', 
     '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

回答

0

有主体数据是错误的。我忘记把索引放在custom_attributes阵列上。

它应该是这样的:

$data = array(
    'customer' => array(
     'id' => 1, 
     'email' => '[email protected]', 
     'firstname' => 'John', 
     'lastname' => 'Doe', 
     'website_id' => 1, 
     'custom_attributes' => array(
      '0' => array(
       'attribute_code' => 'my_custom_attribute_code', 
       'value' => 'my_custom_attribute_value' 
      ) 
     ) 
    ) 
); 
相关问题