Reputation: 4101
I am trying to get the stock status of all products within a particular category. My current code is below but getIsInStock
is not part of the default collection. How can i get this value in the same way as ->addAttributeToSelect('product_type')
$collection = Mage::getModel('catalog/category')->load($_cat_id)->getProductCollection()
->addAttributeToSelect('product_type');
foreach ($collection as $product) {
if( $product->getIsInStock() ) {
print $product->getProductType().' is in stock';
}
}
Upvotes: 0
Views: 226
Reputation: 166
You can join your collection by :
$collection->joinField(
'is_in_stock',
'cataloginventory/stock_item',
'is_in_stock',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
)
let me know if it helpes
Upvotes: 1