[英]How to sort product collection on stock status in magento
我想在類別頁面上對產品集合進行排序,以便有庫存的產品應在無庫存的產品之前出現。 所有缺貨的產品將顯示在有貨的產品之后。 我已經重寫了Mage_Product_Block_List塊。
You can use catalog_product_collection_load_before event.
And in the observer:
public function modifyProductCollection(Varien_Event_Observer $observer) {
//catalog_product_collection_load_before
$collection = $observer->getCollection();
$collection->getSelect()->joinLeft(
array('_inventory_table' => $collection->getTable('cataloginventory/stock_item')),
"_inventory_table.product_id = e.entity_id",
array('is_in_stock')
)
->order('is_in_stock DESC')
->order('created_at DESC');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.