gpt4 book ai didi

php - Magento 产品的 API

转载 作者:可可西里 更新时间:2023-10-31 22:52:03 24 4
gpt4 key购买 nike

我的商店有 magento2,我想使用 REST API 获取所有可配置/简单产品及其子(变体)产品。我能够在单个 REST API 调用中获取所有产品,但它没有为我提供可配置产品的子项。

我需要如下所示的可配置产品:

{
"id":1,
"parent_id":1,
"name":"myProduct",
"is_active":true,
.................
"children_data":[

{
"id":1,
"parent_id":1,
"name":"myProduct",
"is_active":true,
.................
},
{
"id":1,
"parent_id":1,
"name":"myProduct",
"is_active":true,
.................
}
]
}

最佳答案

您需要使用以下 REST API 来获取子数据

GET /V1/configurable-products/{sku}/children

响应:

[
{
"sku": "MH01-XS-Black",
"name": "Chaz Kangeroo Hoodie-XS-Black",
"attribute_set_id": 9,
"price": 52,
"status": 1,
"type_id": "simple",
"created_at": "2015-11-20 08:12:24",
"updated_at": "2015-11-20 08:12:24",
"weight": 1,
"extension_attributes": [],
"product_links": [],
"tier_prices": [],
"custom_attributes": [
{
"attribute_code": "required_options",
"value": "0"
},
{
"attribute_code": "has_options",
"value": "0"
},
{
"attribute_code": "tax_class_id",
"value": "2"
},
{
"attribute_code": "image",
"value": "/m/h/mh01-black_main.jpg"
},
{
"attribute_code": "category_ids",
"value": [
"2",
"15",
"36"
]
},
{
"attribute_code": "size",
"value": "167"
},
{
"attribute_code": "color",
"value": "49"
},
{
"attribute_code": "small_image",
"value": "/m/h/mh01-black_main.jpg"
},
{
"attribute_code": "thumbnail",
"value": "/m/h/mh01-black_main.jpg"
},
{
"attribute_code": "url_key",
"value": "chaz-kangeroo-hoodie-xs-black"
},
{
"attribute_code": "msrp_display_actual_price_type",
"value": "0"
}
]
},
...
]

如果您需要所有可配置选项并调用以下 API

GET /V1/configurable-products/{sku}/options/all

响应:

[
{
"id": 3,
"attribute_id": "90",
"label": "Color",
"position": 0,
"values": [
{
"value_index": 49
},
{
"value_index": 52
},
{
"value_index": 56
}
],
"product_id": 67
},
{
"id": 2,
"attribute_id": "137",
"label": "Size",
"position": 0,
"values": [
{
"value_index": 167
},
{
"value_index": 168
},
{
"value_index": 169
},
{
"value_index": 170
},
{
"value_index": 171
}
],
"product_id": 67
}
]

关于php - Magento 产品的 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38562906/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com