The addVisibleFilterToCollection()
and addSaleableFilterToCollection()
methods of Mage_Catalog_Model_Product_Status
are annotated with @deprecated, but there is no instruction as to what approach to use instead. Code within Magento's core is still using those methods, ref Mage_Catalog_Model_Layer::prepareProductCollection()
.
What approach should be used decorating the collection with the correct visibility/salable filters?
For Visibility there is (from Mage_Catalog_Model_Layer::prepareProductCollection()):
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
Which sets the CATALOG and BOTH filters to the collection.
For Status it appears a bit strange but still makes sense. In _initSelect in app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php The following is done:
$this->getSelect()
->from(array(self::MAIN_TABLE_ALIAS => $this->getEntity()->getFlatTableName()), null)
->columns(array('status' => new Zend_Db_Expr(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)));
This code is executed when doing the
Mage::getResourceModel('catalog/product_collection')
So basically the status ENABLED is already checked when doing the
$category->getProductCollection()
Or similar product collection calls.
Did you tried common approach :
addAttributeToFilter('visibility',Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
addAttributeToFilter('status',1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With