How can I implement stock filter in Magento way?

社会主义新天地 提交于 2019-12-04 19:01:19
Chirag Nandaniya

this is the development work. you need to hire some one.

basically you need to create attribute for product.

eg. 'exclude_out_of_stock'.

then you need to code in Mage/Catalog/Block/Product/List.php

modify function _getProductCollection()

FROM $this->_productCollection = $layer->getProductCollection();

TO

$this->_productCollection = $layer->getProductCollection();

if ($this->getRequest()->getParam('exclude_out_of_stock',0)) {

            $oCollection = Mage::getModel('cataloginventory/stock_item')
                ->getCollection()
                ->addFieldToFilter('is_in_stock',0);

            $oProducts = array();
            foreach($oCollection as $_collection) {
                $oProducts[] = $_collection->getProductId();
            }

            if(!empty($oProducts))
                $this->_productCollection->addIdFilter($oProducts,true);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!