3

I will describe my magento issue as best I can.

I have shoes size filter in Layered Navigation but for some reason when i press ex. "size 43" then the results display shoes that had number 43 and now they are now out of stock or they are available in other sizes.

What I need is the out of stock products to be displayed normal but when i press some of the filters ex."shoes size or shirt size" then out of stock products or products with that filter that have been sold to not be displayed.

I hope that someone has the answer.

Thanks

Steve

  • Can I have the specific to override/extend this class with a module? – Luca Cagnassi Feb 20 at 14:40
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – Jai Feb 20 at 15:27
3

The "Display Out of Stock Products" option set to No will hide products that are completely out of stock. If you want these to be displayed, but also want filters to hide options where the simple product for that option is out of stock, there is a simple solution.

Rather than fiddle about with how the product collection is retrieved and/or displayed, it is simpler to remove these options from the product attribute index. This index is just used for categories so is pretty safe.

In order to not visible simple products that are not configurable children, just add the following join to the _prepareRelationIndex method of Mage/Catalog/Model/Resource/Product/Indexer/Eav/Abstract.php before the insertFromSelect call:

$select->join(
    array('s' => $this->getTable('cataloginventory/stock_item')),
    's.product_id=i.entity_id AND is_in_stock <> 0',
    array()
);

Needless to say, this is a core hack, and so should be actually implemented as a rewrite or observer to prepare_catalog_product_index_select (be careful that this is triggered from other methods too).

As this is making changes to indexing, you'll want to re-run the indexing for catalog_product_attribute (via admin or n98-magerun) and clear the block cache after the code changes are made.

  • awesome! this saved us hours of research! – Haim Jan 25 '17 at 22:24
  • 1
    @Robert Maybe mention the indexer to re-run after this change? – snh_nl Nov 3 '18 at 16:30
  • Anyone had to do this for Magento 2? – Loxzibit May 15 at 17:51
0

Yes you can hide or show's the out of stock product from magento grid product view

it can manage from admin panel follow the following steps

login admin

go to "system"--> "Configuration"

in that goto left side navigation bar "Catalog"--->"Inventory"

then goto right side tabs there is 2 tabs in that click on "Stock Options"

in that tab change "yes" for "Display Out of Stock Products" Option

0

I had the same problem on Magento 1.9 to hide out of stock products from a filter/layered navigation.

Solution:

Simply make changes in

app\design\frontend\foundation\default\template\catalog\layer\filter.phtml

From:

    <ol>
    <?php foreach ($this->getItems() as $_item): ?>
        <li>
            <?php if ($_item->getCount() > 0): ?>
            <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
            <?php else: echo $_item->getLabel() ?>
            <?php endif; ?>
            <?php if ($this->shouldDisplayProductCount()): ?>
            (<?php echo $_item->getCount() ?>)
            <?php endif; ?>
        </li>
    <?php endforeach ?>
    </ol>

To:

    <ol>
    <?php foreach ($this->getItems() as $_item): ?>
    <?php if ($_item->getCount() > 0): ?>
        <li>
            <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
            <?php else: echo $_item->getLabel() ?>
            <?php endif; ?>
            <?php if ($this->shouldDisplayProductCount()): ?>
            (<?php echo $_item->getCount() ?>)
        </li>
    <?php endif; ?>
    <?php endforeach ?>
    </ol>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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