Magento 2 REST API客户自定义属性

问题描述:

Magento 2 REST API文档说明了在更新或创建客户时设置custom_attributes的方法。 http://devdocs.magento.com/swagger/index_20.html#/Magento 2 REST API客户自定义属性

不幸的是我不能得到这个工作...

我POST和PUT JSON请求数据是:创建

{ 
    "customer": { 
     "custom_attributes": [ 
      { 
       "attribute_code": "firstname", 
       "value": "TEST" 
      } 
     ], 
     "email": "[email protected]", 
     "extension_attributes": [], 
     "firstname": "Someone", 
     "gender": null, 
     "lastname": "Else", 
     "middlename": null, 
     "taxvat": null, 
     "website_id": "1" 
    } 
} 

客户,但名字不是 “TEST”。 有没有人遇到同样的问题并修复它?请让我知道如何。

我最好的猜测是,因为Firstname是一个现有的Out-Of-The-Box属性 - 所以OOTB属性名称 - 值映射分配将优先。

你能再试一次,具有独特的自定义属性的名称(即不开箱即用的冲突属性名的东西)

您需要定义一个定制的客户属性,然后才能使用M2 API对该自定义客户属性执行操作。

此StackExchange线程 - https://magento.stackexchange.com/questions/88245/magento2-create-a-customer-custom-attribute - 具有关于如何设置自定义客户属性的附加信息。

+0

我做了与确实有效的项目和属性“描述”完全相同的内容。为什么这不适合客户?我找不到Magento 2代码中处理这个请求的地方,也许你可以提供我的位置? – MmynameStackflow

+0

- 查看为所讨论的方法定义的WebAPI('Magento \ Customer \ etc \ webapi.xml'),'POST/V1/customers' API调用由'Magento \ Customer \ Api \ AccountManagementInterface :: createAccount处理)' - 根据di.xml('Magento \ Customer \ etc \ di.xml')'Magento \ Customer \ Api \ AccountManagementInterface'由'Magento \ Customer \ Model \ AccountManagement'('Magento \ Customer \ Model \ AccountManagement.php') - 我建议使用Xdebug来遍历代码来找出属性不更新的方式/原因。 –

+0

谢谢你解决它@Sharath库马尔。我的结论:这是不可能的,Magento 2不会对客户API上的custom_attributes做任何事情。与产品API不同。我想知道为什么文档说你可以... – MmynameStackflow