I searched the web. But was unable to find any proper guide to create grouped product programmatically.

Can anyone provide proper guide for this?

Links to web posts, books, pdf and any other online guides are highly appreciated.

Thanks in advance

1 Answer 1


The following code worked perfectly for me to create Grouped product with it's associate products. Hope this will help someone to create grouped products programmatically.

public function createGroupedProduct()
        $sku = 'AL108';
        $title = 'my test product';
        $description = 'this is a description about the product...';

        $product = new Mage_Catalog_Model_Product();

        $product->setAttributeSetId(63); // put your attribute set id here.
        $product->setCategoryIds(array(35)); // put your category ids here
        $product->setWebsiteIDs(array(1,2,3));// put your website ids here
                                    'is_in_stock'             => 1,
                                    'manage_stock'            => 0,
                                    'use_config_manage_stock' => 1

        try {
// Save the grouped product.
            $group_product_id = $product->getId();

// You need to create an array which contains the associate product ids.
            $simpleProductId[0] = 1483;
            $simpleProductId[1] = 1484;
            $simpleProductId[2] = 1485;
                $simpleProductId[3] = 1486;
            $simpleProductId[4] = 1487;

            $products_links = Mage::getModel('catalog/product_link_api');

// Get grouped product id.
            $group_product_id = $product->getId();

// Map each associate product with the grouped product.
            foreach($simpleProductId as $id){
                $products_links->assign ("grouped",$group_product_id,$id);

        } catch (Exception $ex) {
            echo $ex->getMessage();

  • feel free to accept the answer if you dont think you will get a better one :) May 25, 2014 at 20:21
  • @DavidManners: Thanks a lot for reminding. I was forgotten this :)
    – Sukeshini
    May 26, 2014 at 4:30

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.