【问题标题】:Magento 2 REST API Customer Custom AttributeMagento 2 REST API 客户自定义属性
【发布时间】:2023-03-06 05:42:02
【问题描述】:

Magento 2 REST API 文档解释了一种在更新或创建客户时设置 custom_attributes 的方法。 http://devdocs.magento.com/swagger/index_20.html#/

不幸的是,我无法让它工作......

我的 POST 和 PUT JSON 请求数据是:

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

客户已创建,但名字不是“TEST”。 有没有人遇到同样的问题并解决了?请告诉我怎么做。

【问题讨论】:

    标签: rest api magento magento2


    【解决方案1】:

    我的最佳猜测是,由于 Firstname 是现有的开箱即用属性 - OOTB 属性名称-值映射分配将优先。

    您能否再试一次,使用唯一的自定义属性名称(即不与 OOTB 属性名称冲突的名称)

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

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

    【讨论】:

    • 我对一个项目和属性“描述”做了完全相同的事情,它确实有效。为什么这对客户不起作用?我在 Magento 2 代码中找不到处理此请求的位置,也许您可​​以提供给我的位置?
    • - 查看为相关方法定义的 WebAPI (Magento\Customer\etc\webapi.xml),POST /V1/customers API 调用由 Magento\Customer\Api\AccountManagementInterface::createAccount() 处理 - 根据 di.xml (Magento\Customer\etc\di.xml) @987654327 @ 由 Magento\Customer\Model\AccountManagement (Magento\Customer\Model\AccountManagement.php) 实现 - 我建议使用 Xdebug 逐步执行代码以找出属性不更新的方式/原因。
    • 感谢您解决问题@Sharath Kumar。我的结论:这是不可能的,而且 Magento 2 对 Customer API 上的 custom_attributes 没有做任何事情。与产品 API 不同。我想知道为什么文档说你可以......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 2012-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多