Search This Blog

Aug 16, 2011

Magento: How to Get Product Collection by Type

Magento composed of 5 product type named as the following: simple, configurable, bundle, grouped, and virtual. Each product type has its own corresponding features that suit on every products that you’re planning to sell. Choosing though, must be done carefully in order to have an easy product management and enable wide range product marketing plan.

To get the collection of product according to their type, do the following code.

Simple Product

$collectionSimple = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToFilter('type_id', array('eq' => 'simple'));
 

Configurable Product

$collectionConfigurable = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToFilter('type_id', array('eq' => 'configurable'));

 

Bundle Product

$collectionBundle = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToFilter('type_id', array('eq' => 'bundle'));
 
 

Grouped Product

$collectionGrouped = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToFilter('type_id', array('eq' => 'grouped'));
  

Virtual Product

$collectionVirtual = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToFilter('type_id', array('eq' => 'virtual'));

 

0 comments: