1

I am trying to get only parent product of a particular manufacurer using product collection Model. I tried below code-

$brand_id=23;  // a manufacturer option value
$manufacturerId = $brand_id;
$attributeCode = 'manufacturer';
$_productCollection= Mage::getModel('catalog/product')
                    ->getCollection()
                    ->addAttributeToFilter($attributeCode, $manufacturerId)
                    ->addAttributeToSelect('name');

below is the screenshot showing what I am trying to do- enter image description here

in above image I am getting all parent + child products. I only want to get parent products. I have used tried this link but no luck, can anyone guide me how can I do that.

2
  • have you created product name attribute? What is relation between product name attribute and brand?
    – Abdul
    Nov 9, 2015 at 8:08
  • How you define a product is parent products.Actually this not default magento feature So i have asking
    – Amit Bera
    Nov 9, 2015 at 9:50

1 Answer 1

1

Change your product collection something like this and try

$_productCollection= Mage::getModel('catalog/product')
                    ->getCollection()
                    ->addAttributeToFilter($attributeCode, $manufacturerId)
                    ->addAttributeToSelect('name');

$_productCollection->joinTable('catalog/product_relation', 'child_id=entity_id', array(
            'parent_id' => 'parent_id'
        ), null, 'left')
        ->addAttributeToFilter(array(
            array(
                'attribute' => 'parent_id',
                'null' => null
            )
        ));

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.