03 May 2017
Out Of Stock Products To The End Of The List In Magento Category Page
Step 1 : Using your file explorer copy file Layer.php from app/code/core/Mage/Catalog/Model/ and paste to app/code/local/Mage/Catalog/Model/
Step 2 : Open the newly copied file i.e., app/code/local/Mage/Catalog/Model/Layer.php using your code editor such as Notepad or Sub Lime
Step 3 : Search for the function getProductCollection(), which needs to be inserted with a below query
$collection->getSelect()->joinLeft(array('stock_status'=>$collection->getTable('cataloginventory/stock_status')),'e.entity_id = stock_status.product_id AND stock_status.website_id='.Mage::app()->getWebsite()->getId());
$collection->getSelect()->order('stock_status DESC');
public function getProductCollection()
{
if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
$collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
} else {
$collection = $this->getCurrentCategory()->getProductCollection();
/********************** QUERY TO DISPLAY OUT OF STOCK PRODUCTS TO THE END OF LIST IN CATEGORY PAGE ***********************/
$collection->getSelect()->joinLeft(array('stock_status' => $collection->getTable('cataloginventory/stock_status')),'e.entity_id = stock_status.product_id AND stock_status.website_id='.Mage::app()->getWebsite()->getId());
$collection->getSelect()->order('stock_status DESC');
$this->prepareProductCollection($collection);
$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
}
return $collection;
}
Share this Article on
Tags: magento,
RELATED POSTS