문제

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...

도움이 되었습니까?

해결책

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top