Add group product in cart magento


$productModel = Mage::getModel('catalog/product');
$super_group = array();
$parentId = $params['productid'];
$qty = 1;
// $parentId =  
$parentProduct = $product_model->load($parentId);
$associatedProducts = $parent_prod->getTypeInstance()->getAssociatedProducts();
//set quantity of associate product
 foreach ($associatedProducts as $product) {
            $array[$product->getId()] = $qty;
        }
$params['super_group'] = $array;
$product = Mage::getModel('catalog/product')->load($parentId);
//check product availability
if (!$product) {
                echo "Error";
                return;
          }
// create cart object
 $cart = Mage::getModel('checkout/cart');
$param = array('super_group' => $super_group);
 //Add product to cart with specified parameters 
$cart->addProduct($product, $params);
//and save the cart object
$cart->save();
//update cart
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s