0

Is there a way to show only in stock product count in shop by layered navigation filters? i need to show out of stock products in frontend, But not need to include its count in filters such as shop by price, shop by category etc. Is there any possible way? i have checked the code. But struggling to achieve. Any help would be appreciated.

| improve this question | | | | |
0

Mage_Catalog_Model_Layer_Filter_Attribute in this function count the product for filter

protected function _getItemsData()
{
    $attribute = $this->getAttributeModel();
    $this->_requestVar = $attribute->getAttributeCode();

    $key = $this->getLayer()->getStateKey() . '_' . $this->_requestVar;
    $data = $this->getLayer()->getAggregator()->getCacheData($key);

    if ($data === null) {
        $options = $attribute->getFrontend()->getSelectOptions();
        $optionsCount = $this->_getResource()->getCount($this);
        $data = array();
        foreach ($options as $option) {
            if (is_array($option['value'])) {
                continue;
            }
            if (Mage::helper('core/string')->strlen($option['value'])) {
                // Check filter type
                if ($this->_getIsFilterableAttribute($attribute) == self::OPTIONS_ONLY_WITH_RESULTS) {
                    if (!empty($optionsCount[$option['value']])) {
                        $data[] = array(
                            'label' => $option['label'],
                            'value' => $option['value'],
                            'count' => $optionsCount[$option['value']],
                        );
                    }
                } else {
                    $data[] = array(
                        'label' => $option['label'],
                        'value' => $option['value'],
                        'count' => isset($optionsCount[$option['value']]) ? $optionsCount[$option['value']] : 0,
                    );
                }
            }
        }

        $tags = array(
            Mage_Eav_Model_Entity_Attribute::CACHE_TAG . ':' . $attribute->getId()
        );

        $tags = $this->getLayer()->getStateTags($tags);
        $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags);
    }

    return $data;
}

protected function _getCount($var)
{
    // Clone the select
    $select = clone $this->getLayer()->getProductCollection();

    $pid1 = $select->getAllIds();
    $products = Mage::getModel('catalog/product')->getCollection()
        ->joinField('rating_summary',
            'review_entity_summary',
            'rating_summary',
            'entity_pk_value=entity_id',
            array('entity_type' => 1, 'store_id' => Mage::app()->getStore()->getId()),
            'left'
        )
        ->addAttributeToFilter('entity_id', array('in' => $pid1))
        ->load();

    return count($products);
}
| improve this answer | | | | |
0

Rewrite the model

app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Attribute.php

and override the method getCount()

| improve this answer | | | | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.