Under Configuration -> Inventory -> Display Out of Stock Products I have set it to Yes because out of stock products are accessible by Search Engines though I don't want the out of stock products to show up in Upsell section. Is there any way to achieve this by applying filters? Below is the entire code of my upsell.phtml.

<?php if (count($this->getItemCollection()->getItems())): ?>

    <div class="collateral-box up-sell">

        <div class="head"><h4><?php echo $this->__('You may also be interested in the following product(s):') ?></h4></div>

        <table cellspacing="0" class="generic-product-grid catalog-listing" id="upsell-product-table">

            <?php // $this->setColumnCount(4); // uncomment this line if you want to have another number of columns. also can be changed in layout ?>

            <?php $this->resetItemsIterator() ?>

            <?php for ($_i = 0; $_i < $this->getRowCount(); $_i++): ?>


                    <?php for ($_j = 0; $_j < $this->getColumnCount(); $_j++): ?>

                        <?php if ($_link = $this->getIterableItem()): ?>

                            <?php $_link = Mage::getModel('catalog/product')->load($_link->getId()); ?>


                                <p class="product-image"><a href="<?php echo $_link->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_link, 'small_image')->resize(125) ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_link->getName()) ?>" /></a></p>

                                <h5><a href="<?php echo $this->getUrl($_link->getUrlPath()) ?>"><?php echo $this->htmlEscape($_link->getName()) ?></a></h5>

                                <?php //echo $this->getPriceHtml($_link, true) ?>

                                <?php //echo $this->getReviewsSummaryHtml($_link) ?>


                        <?php else: ?>

                            <td class="empty-product">&nbsp;</td>

                        <?php endif; ?>

                    <?php endfor; ?>


            <?php endfor; ?>


        <script type="text/javascript">decorateTable('upsell-product-table')</script>


<?php endif ?> 

1 Answer 1


You can observe this event catalog_product_upsell.
It receives as a parameter the list of upsell products. You can check if they are out of stock and remove them from the collection.

public function filterUpsells($observer) {
    $collection = $observer->getEvent()->getCollection();
    foreach ($collection as $item) {
        if (!$item->getIsSalable()) {
  • Thanks, can you be more specific as I am very new to Magento and php?
    – Kevin S
    Mar 6, 2014 at 12:37
  • @KevinS. This could help a lot: magentocommerce.com/wiki/5_-modules_and_development/0-_module_development_in_magento/customizing_magento_using_event-observer_method
    – Marius
    Mar 6, 2014 at 12:40
  • I did visited the link and it says You’ve followed a link to a topic that doesn’t exist yet. If permissions allow, you may create it by using the “Create this page” button.
    – Kevin S
    Mar 6, 2014 at 12:41
  • @KevinS. Don't click it. Copy/paste it in your browser. For some reason the SO wiki parser is cutting the link. The link ends with 'method'. Just copy it all "www.magentocommerce.com/wiki/5_-modules_and_development/0-_module_development_in_magento/customizing_magento_using_event-observer_method"
    – Marius
    Mar 6, 2014 at 12:44
  • @KevinS Damn it...I can't seam to post the link properly. Just google "magento event observer" and click on the first link.
    – Marius
    Mar 6, 2014 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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