簡體   English   中英

獲取可配置產品 Magento 2.0 REST Api 的所有選項

[英]Get all options for configurable product Magento 2.0 REST Api

當我調用這個 API 時,

{{base_url}}index.php/rest/V1/configurable-products/:sku/options/all

我收到這樣的回復

[
  {
    "id": 9,
    "attribute_id": "93",
    "label": "Color",
    "position": 0,
    "values": [
      {
        "value_index": 15
      },
      {
        "value_index": 16
      },
      {
        "value_index": 17
      }
    ],
    "product_id": 19
  },
  {
    "id": 10,
    "attribute_id": "176",
    "label": "side",
    "position": 1,
    "values": [
      {
        "value_index": 18
      },
      {
        "value_index": 19
      }
    ],
    "product_id": 19
  }
]

但我想要所有這些 value_indexes 的標簽。我可以在一個請求中獲得所有這些值嗎

有一個用於獲取所有標簽的pi,

{{base_url}} / index.php / rest / V1 / products / attributes /:attribute_id / options

例如:

{{base_url}} / index.php / rest / V1 / products / attributes / 93 / options

將返回

[
  {
    "label": " ",
    "value": ""
  },
  {
    "label": "green",
    "value": "12"
  },
  {
    "label": "yellow",
    "value": "13"
  },
  {
    "label": "red",
    "value": "14"
  }
]

您可以使用此端點在單個請求/rest/V1/products/attributes獲取多個屬性集

例子:

{domain}/rest/V1/products/attributes?search_criteria[filter_groups][0][filters][0][field]=attribute_id&search_criteria[filter_groups][0][filters][0][value]=93,138&search_criteria[filter_groups][0][filters][0][condition_type]=in

回復:

    "items": [
        {
            "is_wysiwyg_enabled": false,
            "is_html_allowed_on_front": false,
            "used_for_sort_by": false,
            "is_filterable": true,
            "is_filterable_in_search": false,
            "is_used_in_grid": true,
            "is_visible_in_grid": false,
            "is_filterable_in_grid": true,
            "position": 0,
            "apply_to": [
                "simple",
                "virtual",
                "configurable"
            ],
            "is_searchable": "1",
            "is_visible_in_advanced_search": "1",
            "is_comparable": "1",
            "is_used_for_promo_rules": "0",
            "is_visible_on_front": "0",
            "used_in_product_listing": "0",
            "is_visible": true,
            "scope": "global",
            "attribute_id": 93,
            "attribute_code": "color",
            "frontend_input": "select",
            "entity_type_id": "4",
            "is_required": false,
            "options": [
                {
                    "label": " ",
                    "value": ""
                },
                {
                    "label": "blue",
                    "value": "8"
                },
                {
                    "label": "red",
                    "value": "9"
                },
                {
                    "label": "black",
                    "value": "10"
                },
                {
                    "label": "white",
                    "value": "11"
                }
            ],
            "is_user_defined": true,
            "default_frontend_label": "Color",
            "frontend_labels": [],
            "backend_type": "int",
            "source_model": "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table",
            "default_value": "",
            "is_unique": "0",
            "validation_rules": []
        },
        {
            "is_wysiwyg_enabled": false,
            "is_html_allowed_on_front": true,
            "used_for_sort_by": false,
            "is_filterable": false,
            "is_filterable_in_search": false,
            "is_used_in_grid": true,
            "is_visible_in_grid": true,
            "is_filterable_in_grid": true,
            "position": 0,
            "apply_to": [],
            "is_searchable": "0",
            "is_visible_in_advanced_search": "0",
            "is_comparable": "0",
            "is_used_for_promo_rules": "0",
            "is_visible_on_front": "0",
            "used_in_product_listing": "0",
            "is_visible": true,
            "scope": "global",
            "attribute_id": 138,
            "attribute_code": "simple_size",
            "frontend_input": "select",
            "entity_type_id": "4",
            "is_required": true,
            "options": [
                {
                    "label": " ",
                    "value": ""
                },
                {
                    "label": "small",
                    "value": "12"
                },
                {
                    "label": "medium",
                    "value": "13"
                },
                {
                    "label": "large",
                    "value": "14"
                }
            ],
            "is_user_defined": true,
            "default_frontend_label": "simple_size",
            "frontend_labels": [
                {
                    "store_id": 1,
                    "label": "Size"
                }
            ],
            "backend_type": "int",
            "source_model": "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table",
            "default_value": "",
            "is_unique": "0",
            "validation_rules": []
        }
    ],
    "search_criteria": {
        "filter_groups": [
            {
                "filters": [
                    {
                        "field": "attribute_id",
                        "value": "93,138",
                        "condition_type": "in"
                    }
                ]
            }
        ]
    },
    "total_count": 2
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM