How can I implement stock filter in Magento way?

旧城冷巷雨未停 提交于 2019-12-09 23:31:38

问题


Out of stock products are visible in my magento website. I want a custom filter in the layered navigation which would say "Exclude out of stock" and when customer clicks on it the out of stock products should be hidden.

(by default I enable showing/displaying out of stock products under System-> Configuration-> CATALOG-> Inventory)

i.e. I want the customer to control whether he/she should see the "out of stock" products or not.

example this link

can anyone help please? I want this to be done in magento way...


回答1:


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);
}


来源:https://stackoverflow.com/questions/14290431/how-can-i-implement-stock-filter-in-magento-way

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