Magento – How to Get All Simple Products Without Configurable Product

configurable-productproductsimple-product

i want collection of those product which remain as simple product.

in other world i got all simple product which is include in configurable now i just want those product which does not included in configurable and still alone.

Best Answer

This is just an adaptation of what Amit Bera answered.
I just took the code and transformed it into one single query instead of 2.
The idea is to join left the products table with the table that keeps the relation between simple and configurable, and filter only the products that don't have such a relation:

$collection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('type_id', array('eq' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE))
    ->addAttributeToSelect('*'); //or just the attributes you need

$collection->getSelect()->joinLeft(array('link_table' => $collection->getTable('catalog/product_super_link')),
    'link_table.product_id = e.entity_id',
    array('product_id')
);
$collection->getSelect()->where('link_table.product_id IS NULL');

now you just need to loop through the collection.

foreach ($collection as $product) {
     //do something with $product
}