I want to get a collection of products from magento in a specific order.
- Simple Products
- Configurable Products
- Grouped Products
How would I add a filter that will retrieve the products in that order
I want to get a collection of products from magento in a specific order.
How would I add a filter that will retrieve the products in that order
It's not possible directly. I have 2 solutions:
1. Get your products in 3 different collections using addAttributeToFilter
where attribute name
is type_id
. For the condition you can use Mage_Catalog_Model_Product_Type::TYPE_SIMPLE
, Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
and Mage_Catalog_Model_Product_Type::TYPE_GROUPED
.
Example:
$simple_products = $model->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', Mage_Catalog_Model_Product_Type::TYPE_SIMPLE);
2. Add custom attribute from the admin panel (e.g. 1
for simple, 2
for configurable, 3
for grouped products etc.) and use it with addAttributeToSort
.