0

I need get a list of grouped products with a singular product.

For example:

I have the single product A and I have the grouped products B,C,D and E.

Only B and E have the single product A associated.

How can i do this?.

I can retrieve the list of all grouped products and do a bucle to get all associate products and compare with simple product but not is a good practice for the performance I think.

Any idea?.

Thank you.

3 Answers 3

0

SOLVED:

I'm recovering the parents id with this:

Mage::getResourceSingleton('catalog/product_link')
                            ->getParentIdsByChild($_product->getId(), Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED)

Then i have the all grouped products of a product

0

Working Code:-

$associatedProduct = array();
    $products = Mage::getModel('catalog/product')
            ->getCollection()
            ->addAttributeToFilter('type_id', array('eq' => 'grouped'));
    foreach ($products as $product) {
        $associatedProduct[] = $product->getTypeInstance(true)->getAssociatedProduct($product);
    }



    foreach ($associatedProduct as $singleProduct) {
        foreach ($singleProduct as $product) {
           echo $product->getName().'<br/>';
        }
    }
0

Suppose product A = $simpleproduct.

$groupParentsIds = Mage::getResourceSingleton('catalog/product_link')->getParentIdsByChild($simpleproduct->getId(), Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED);

Now you will get all the group parent ids who have associated product A. After that you can load the parent products from their ids according to your requirement.

Hope this helps.

2
  • If u see I answer my ask with "SOLVED" and is the same solution....
    – str_lml
    Commented May 11, 2018 at 7:54
  • Mark the question as solved. Commented May 11, 2018 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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