问题
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