![](/img/trans.png)
[英]Products not showing up in category after enabling Solr on Magento 1.14 EE
[英]Bestsellers not showing after enabling flat category and products
我有一個代碼來顯示我們商店中最暢銷的產品。 如果我禁用扁平化類別和扁平化產品,則該代碼效果很好。 有沒有一種方法可以在不禁用扁平產品和類別的情況下進行此工作。 謝謝...
class Mage_Catalog_Block_Product_Viewed extends Mage_Catalog_Block_Product_Abstract{
public function __construct(){
parent::__construct();
$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addMinimalPrice()
->addAttributeToSelect('*')
->addAttributeToSelect(array('name', 'price', 'small_image'))
->setStoreId($storeId)
->addStoreFilter($storeId)
->setOrder(‘ordered_qty’, ‘desc’);
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
$products->setPageSize(15)->setCurPage(1);
$this->setProductCollection($products);
}
}
請確保在Magento管理員(目錄>管理屬性)中將查詢需要返回的所有產品屬性標記為“產品列表中使用的產品” = YES。 僅當設置了此選項(或其他幾個選項)時,屬性才成為Flat表的一部分,這是啟用Flat目錄時的主要區別之一。
您可以對集合的查詢進行Mage :: log()選擇,並查看打開和關閉平面目錄的區別,這將有助於您理解差異並進行調試:
$products->setPageSize(15)->setCurPage(1);
$products->load(); // this is needed only for debugging,
// to get the "real" database query
// PLEASE remove this and Mage::log
// in production as it would affect performance
Mage::log( (string)$products->getSelect() );
$this->setProductCollection($products);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.