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:

Nice article on magento thank you for sharing it with us.
Nice explanation this post will really help every magento developer while fixing bug
The latest versions of magento seem to not have this bug anymore, but for those of us stuck with old installs, thank you!
Thanks for Giving the coding example.. Magento is best opensource for ecommerce development
Leave your response!
Support
Latest Project
Our Work
Popular Tags
Recent Comments
Categories
Services
© 2009 Asia-Connect.com.vn. All Rights Reserved. Powered by WordPress | Log in