簡體   English   中英

在Magento中,擴展rest / products api的性能是什么,檢索返回列表中產品的標簽和屬性?

[英]In Magento, what's the performance of extending the rest/products api, to retrieve the tags and attributes of the products in the returned list?

我能想到的唯一方法是檢索產品,然后在腳本中調用其他API來檢索我需要的信息,最后返回響應。

我對Magento還是有點新鮮,而且這在性能上似乎相當沉重。 以上解決方案在性能方面是否有效,或者是否有更好的方法從其余/產品api中檢索標簽等。

從本質上講,我正在尋找的東西是這樣的:

當前的API返回:

{
337: {
    entity_id: "337"
    type_id: "simple"
    sku: "ace000"
    color: "15"
    gender: "93"
    material: "130"
    jewelry_type: null
    description: "Gunmetal frame with crystal gradient polycarbonate lenses in grey. "
    meta_keyword: null
    short_description: "A timeless accessory staple, the unmistakable teardrop lenses of our Aviator sunglasses appeal to everyone from suits to rock stars to citizens of the world."
    name: "Aviator Sunglasses"
    meta_title: null
    meta_description: null
    regular_price_with_tax: 319.34
    regular_price_without_tax: 295
    final_price_with_tax: 319.34
    final_price_without_tax: 295
    is_saleable: true
    image_url: "http://magentogs.cloudapp.net/magento/media/catalog/product/cache/0/image/9df78eab33525d08d6e5fb8d27136e95/a/c/ace000a_1.jpg"
    }
}

我想添加以下內容(作為示例),**包括顯示我想要添加的內容的東西。

{
337: {
    entity_id: "337"
    type_id: "simple"
    sku: "ace000"
    color: "15"
    gender: "93"
    material: "130"
    jewelry_type: null
    description: "Gunmetal frame with crystal gradient polycarbonate lenses in grey. "
    meta_keyword: null
    short_description: "A timeless accessory staple, the unmistakable teardrop lenses of our Aviator sunglasses appeal to everyone from suits to rock stars to citizens of the world."
    name: "Aviator Sunglasses"
    meta_title: null
    meta_description: null
    regular_price_with_tax: 319.34
    regular_price_without_tax: 295
    final_price_with_tax: 319.34
    final_price_without_tax: 295
    is_saleable: true
    image_url: "http://magentogs.cloudapp.net/magento/media/catalog/product/cache/0/image/9df78eab33525d08d6e5fb8d27136e95/a/c/ace000a_1.jpg"
    **tags: [tag1,tag2,tag3]**
    **categories: [category1,category2,category3]**
    }
}

您應該擴展現有產品REST api模型並覆蓋方法_prepareProductForResponse以包含標記和其他數據

點擊這里覆蓋其他模型http://web.archive.org/web/20130512072025/http://magepim.com/news/Extending-the-Magento-REST-API-part-1_13

你的模型定義:

Namespace_yourmodule_Model_Catalog_Api2_Product_Rest extends Mage_Catalog_Model_Api2_Product_Rest {


protected function _prepareProductForResponse(Mage_Catalog_Model_Product $product)
{
 // keep the existing code as it is

 // now add new code to add tags

 $productData['tags'] = Mage::getModel('tag/tag')->getResourceCollection()
    ->addPopularity()
    ->addProductFilter($product->getId());


// in the end 
 $product->addData($productData);
}

暫無
暫無

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

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