Home » Magento Customization, Magento Guide

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

14 September 2009 One Comment

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. How to make TinyMCE work with Magento CMS pages
  5. Custom category menu navigation in Magento

One Comment »

  • Magento Development said:

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

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: