1

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.

  • 1
    you mean to say you want to display only the products which are not related with configurable products ?? – dh47 Nov 25 '14 at 4:54
  • yes dh47 you get the point. – JACK Nov 25 '14 at 5:12
12

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' => '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
}
  • 1
    ,Thanks for short solution . One upvote from me – Amit Bera Nov 25 '14 at 7:32
3

Magento has simple and configurable product relation in catalog_product_super_link table. So you can use advantage from this table.

Basically what you have to do is, filter the simple product collection by the product ids present in catalog_product_super_link table

Step1: Get list of all simple products by using below code

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

$collectionSimple ->getSelect()->join(array(
    'link_table' => 'catalog_product_super_link'),
    'link_table.product_id = e.entity_id',
    array('product_id')
));

$IdsSimpleCon=$collectionSimple->getAllIds();

enter image description here

Step2: Make another product Collection exclude of step one product collection and code

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

echo $NonConfigurablecollectionSimple->getSelect(); 

Now, $NonConfigurablecollectionSimple would hold all those simple product which does not have a single relationship with configurable products.

  • Hey Amit, good answer. Could you please let me know what is the purpose of catalog_product_super_link. I never used this table before. – Rajeev K Tomy Feb 20 '15 at 0:52
0

you can use the type id to check simple or configurable product. Please refer the below code

$product->getTypeId() == "simple"
  • you did't get my question. i want only those product which not include in configurable. your code give all simple product. – JACK Nov 25 '14 at 5:11
0

Just to complete on what Marius answered, this works for Grouped products:

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

$collection->getSelect()->joinLeft(array('link_table' => 'catalog_product_link'),
  'link_table.linked_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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.