Magento Collection Filter by Visible Products
f you are working on a custom project you might want to create a custom block and only show products that are visible. To do this is actually very simple in Magento. All you need to do is use the following code:
1 2 3 |
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*'); $collection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED); $collection->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); |
Don’t spend time re-inventing the wheel. Have a look at our Magento … Read more