Magento- issaleable filter

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

puts a filter and shows the products that are in stock, but always show configurable products even if they are not in stock (since they are always in stock, but isSaleable gets false when their related products end.) So, how can I apply a filter IsSaleable in a Product Collection? (This can be done directly in the product collection without repeating through the collection. Lack of inventory means that inventory has run out.

+4
source share
2 answers

This should only give you a catalog of the available 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(); 
+4
source

After

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

make

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

Must work.

-1
source

Source: https://habr.com/ru/post/1382734/


All Articles