sushantsahay
sushantsahay

Reputation: 361

Magento- issaleable filter

Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products); 

puts a filter and shows the products which are in stock, But always show configurable products-even when they are out of stock(AS they are always in stock but isSaleable gets false when their associated products gets over.) So How can I apply a IsSaleable filter on a product collection? (can it be done directly on a product collection without iterating through the collection. Out of stock means inventory is over.

Upvotes: 4

Views: 9892

Answers (2)

shook
shook

Reputation: 76

This should give you just catalog visible simple products that are in stock.

$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToFilter('status', 1); // enabled
$products->addAttributeToFilter('type_id', 'simple');
//$products->addAttributeToFilter('sku', array('1234')); //for testing purposes
$products->addAttributeToSelect('*');
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($products);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);
$prodIds = $products->getAllIds();

Upvotes: 4

Nasaralla
Nasaralla

Reputation: 1839

After

Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);

do

$products->addAttributeToFilter('is_saleable', TRUE);

Should work.

Upvotes: -1

Related Questions