Portal Home > Knowledgebase > Magento > How to fix the Magento Out of stock bug, version 1.1.x


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




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:

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

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

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

 



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read