Home Magento Customization, Magento Guide

How to fix the Magento Out of stock bug, version 1.1.x

14 September 2009 4 Comments

This is a popular bug that has been plaguing many people with their custom Magento solutions.

Problem: Magento shows products that are in stock as “Out of Stock” – It seems to be popularly reported within the New Product block.

Solution: The attribute “status” has not been selected in the product collection. This status attribute holds the information about whether or not the product is or is not in stock (among other items that determine if the item should be sale-able).

This attribute needs to be selected via the new product block code.

Find: app/code/core/Mage/Catalog/Block/Product/New.php
You will see:


$products   = $product->setStoreId($storeId)->getCollection()
->addAttributeToFilter('news_from_date', array('date'=>true, 'to'=> $todayDate))
->addAttributeToFilter(array(array('attribute'=>'news_to_date', 'date'=>true, 'from'=>$todayDate), array('attribute'=>'news_to_date', 'is' => new Zend_Db_Expr('null'))),'','left')
->addAttributeToSort('news_from_date','desc')
->addAttributeToSelect(array('name', 'price', 'small_image'), 'inner')
->addAttributeToSelect(array('special_price', 'special_from_date', 'special_to_date'), 'left')
;

You need to add: ‘->addAttributeToSelect(’status’);’


$products   = $product->setStoreId($storeId)->getCollection()
->addAttributeToFilter('news_from_date', array('date'=>true, 'to'=> $todayDate))
->addAttributeToFilter(array(array('attribute'=>'news_to_date', 'date'=>true, 'from'=>$todayDate), array('attribute'=>'news_to_date', 'is' => new Zend_Db_Expr('null'))),'','left')
->addAttributeToSort('news_from_date','desc')
->addAttributeToSelect(array('name', 'price', 'small_image'), 'inner')
->addAttributeToSelect(array('special_price', 'special_from_date', 'special_to_date'), 'left')
->addAttributeToSelect('status');
;

By Fido from exploremagento.com

Related posts:

  1. Some custom Blocks to help you show products
  2. Editing the Footer in a stock magento build
  3. Bestseller module (with Toolbar!) – Magento 1.2.1
  4. Custom category menu navigation in Magento
  5. How to make TinyMCE work with Magento CMS pages

4 Comments »

  • Magento Development said:

    Nice article on magento thank you for sharing it with us.

  • Magento developer said:

    Nice explanation this post will really help every magento developer while fixing bug :)

  • Julian Sutter said:

    The latest versions of magento seem to not have this bug anymore, but for those of us stuck with old installs, thank you!

  • Magento said:

    Thanks for Giving the coding example.. Magento is best opensource for ecommerce development

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree

Security Code: