在Magento 2 REST Api中获取具有自定义属性的所有类别

时间:2017-06-20 10:48:27

标签: php rest magento magento2

我正在使用Magento 2 rest api列出所有的灾难。

{{production_url}} / index.php的/休息/ V1 /类别

它将返回所有类别,

{
    "id": 2,
    "parent_id": 1,
    "name": "Default Category",
    "is_active": true,
    "position": 1,
    "level": 1,
    "product_count": 0,
    "children_data": [{
        "id": 3,
        "parent_id": 2,
        "name": "T-shirts",
        "is_active": true,
        "position": 1,
        "level": 2,
        "product_count": 8,
        "children_data": []
    }, {
        "id": 4,
        "parent_id": 2,
        "name": "Phants",
        "is_active": true,
        "position": 2,
        "level": 2,
        "product_count": 0,
        "children_data": []
    }, {
        "id": 5,
        "parent_id": 2,
        "name": "Chridar",
        "is_active": true,
        "position": 3,
        "level": 2,
        "product_count": 0,
        "children_data": []
    }]
}

但是我需要为结果中的每个类别定制属性。但是现在我必须调用下面的api来获取自定义属性。

{{production_url}} / index.php的/休息/ V1 /类别/ 3

它会返回,

{
    "id": 3,
    "parent_id": 2,
    "name": "T-shirts",
    "is_active": true,
    "position": 1,
    "level": 2,
    "children": "",
    "created_at": "2017-06-02 11:21:16",
    "updated_at": "2017-06-02 11:21:16",
    "path": "1/2/3",
    "available_sort_by": [],
    "include_in_menu": true,
    "custom_attributes": [
        {
            "attribute_code": "description",
            "value": "<p>retest</p>"
        },
        {
            "attribute_code": "image",
            "value": "Screen_Shot_2017-06-16_at_4.06.35_PM.png"
        },
        {
            "attribute_code": "display_mode",
            "value": "PRODUCTS"
        },
        {
            "attribute_code": "is_anchor",
            "value": "1"
        },
        {
            "attribute_code": "path",
            "value": "1/2/3"
        },
        {
            "attribute_code": "children_count",
            "value": "0"
        },
        {
            "attribute_code": "custom_use_parent_settings",
            "value": "0"
        },
        {
            "attribute_code": "custom_apply_to_products",
            "value": "0"
        },
        {
            "attribute_code": "url_key",
            "value": "redwine"
        },
        {
            "attribute_code": "url_path",
            "value": "redwine"
        }
    ]
}

假设有 n 的灾难,我需要调用 n api来获取自定义属性。是否有任何单一的API来获取所有单个API中所有类别的属性?

2 个答案:

答案 0 :(得分:2)

Magento Api CatalogTreeInterface不会扩展Magento \ Framework \ Api \ ExtensibleDataInterface,这意味着无法将自定义属性或扩展属性添加到树响应中。我唯一的解决方法是创建自己的模块和一个新的api调用,扩展树界面以添加我的自定义属性。

答案 1 :(得分:0)

我想鲁本是对的。我已经构建了Magento扩展,以将图像属性添加到类别树,请看看https://github.com/troublediehard/mma-customapi