簡體   English   中英

使用 REST API 在 Magento 中顯示類別及其子類別

[英]Display categories and their subcategories in Magento using REST API

任何人都可以幫助我使用 REST API 顯示類別及其子類別嗎?

我試過這個網址:

http://localhost/magento/api/rest/products/:productId/categories

但它顯示類別ID而不是我需要的,即這樣的東西:

http://localhost/magento/api/rest/categories

提前致謝。

/api/rest/products/:productId/categories

這應該檢索分配給特定產品的類別列表。 不幸的是,這不會引導您找到您應得的優雅解決方案。

如果您想要一個類別列表,您可能必須使用soap api使用catalog_categories.tree 方法檢索類別。 我意識到“使用其他 api”是最糟糕的答案,但是,這是 Magento 目前提供的。

另一種選擇是使用您自己的寧靜拼湊來擴展庫存 api,但是,生命是短暫的。

如果你真的想做這樣的事情,那么另一個堆棧溢出問題將幫助你開始: 創建新的 magento Rest api to get category list in magento

Magento 1.x API 指南或代碼中確實仍然沒有找到任何內容。

您可以在Mage_Catalog模塊的文件夾結構中清楚地看到,表示類別的模型仍然只是產品的子模型,因此其主要目標仍然是“僅”能夠知道特定產品鏈接到哪些類別。

REST API 模型的 Magento 文件夾結構

Mage_Catalog_Model_Api2_Product_Category_Rest是,這個類別模型的代碼屬於Mage_Catalog_Model_Api2_Product_Category_Rest類,看起來與之前的答案沒有任何變化(最新版本 1.9.2.4 中的第 61 行左右):

protected function _retrieveCollection()
{
    $return = array();

    foreach ($this->_getCategoryIds() as $categoryId) {
        $return[] = array('category_id' => $categoryId);
    }
    return $return;
}

而且我不確定 Magento 是否仍會在框架的 1.x 版上為 REST API 付出任何努力。

盡管Magento 2.x API 列表中似乎有希望列出這些可用方法:

刪除 /V1/categories/:categoryId
獲取 /V1/categories/:categoryId
POST /V1/categories
獲取/V1/類別
PUT /V1/categories/:id
PUT /V1/categories/:categoryId/move

該代碼還提供了獲取類別樹的可能性。
這里那里

所以在 Magento 2.x 下絕對是可能的

暫無
暫無

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

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