2017-09-16 106 views
0

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」。 有沒有人遇到同樣的問題並修復它?請讓我知道如何。

回答

1

我最好的猜測是,因爲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