Magento PHP : Products without parents

1k Views Asked by At

In Magento, on a script I would like to filter the products who don't have any parent product. Currently I do something like :

$products = $this->_productModel->getCollection()
    ->addAttributeToSelect('*')
    ->addStoreFilter($this->_storeId)
    ->addAttributeToFilter('type_id',array('in'=>$_types))
    ->addAttributeToFilter('status',array('in'=>$_status))
    ->joinTable('cataloginventory/stock_item', 'product_id=entity_id', array('qty'=>'qty','is_in_stock' => 'is_in_stock'), $this->_getStockSQL(), 'inner');

I got all the products, but can I say "give me only the products without parents" using getCollection() ?

Thanks

2

There are 2 best solutions below

0
On

Perfect :)

->joinTable('catalog_product_relation', "parent_id=entity_id",array('child_id'=>'child_id'), null, "inner")

Thanks

0
On

Parent product and child product are only avialable in grouped, configurable, and bundle product. If you don't want parent product

Check if id is in parent_id in catalog_product_relation and catlog_product_super_link then its a parent product