2017-06-20 114 views
1

我正在使用Magento 2 rest api列出所有分類。使用Magento 2中的自定義屬性獲取所有類別REST Api

{{production_url}}/index.php文件/ REST/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文件/ REST/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 catgories我需要調用n api獲取自定義屬性。是否有任何單個api獲取單個API中所有類別的所有屬性?

回答

0

Magento Api CatalogTreeInterface不擴展Magento \ Framework \ Api \ ExtensibleDataInterface,這意味着自定義屬性或擴展屬性不能添加到樹響應中。唯一的解決方法是創建我自己的模塊和一個新的api調用,它擴展了樹接口以添加我的自定義屬性。

相關問題