<?php
   
class Mageguru_AddMultipleProducts_AddController extends Mage_Core_Controller_Front_Action 
{   
	public function indexAction() 
		{ 
			print_r($_REQUEST);
			$super_attribute=$_REQUEST['super_attribute'];
			$itr_count=$_REQUEST['c_str'];
			foreach($super_attribute as $index=>$val)
			{
				echo $index;
				$j=1;
				for($i=1;$i<=$itr_count;$i++)
				{
					echo $name='super_attribute_'.$index.'_'.$i;
					echo "<br>";
					if(isset($_REQUEST[$name]))
					{
						if($i==$itr_count)  :
						$off_set=$itr_count;
						$att_arr[$index.$off_set]=$_REQUEST[$name];
						else :
						$att_arr[$index.$i]=$_REQUEST[$name];
						endif;
						$j++;
					}
				}
			}
			//echo "-->>The process";
			//echo "<br>";
			$product_id=$_REQUEST['product'];
			$cart = Mage::getModel('checkout/cart'); 
			$cart->init();
			$super_attribute_arr=array();			
					if ($product_id == '') 
					{ continue; } 
					$pModel = Mage::getModel('catalog/product')->load($product_id); 
					if ($pModel->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) 
					{ 
						try 
						{ 	
							for($q=1; $q<=$itr_count; $q++)
							{
								//echo $q;
								$p= Mage::getModel('catalog/product')->load($product_id); 								
								foreach($super_attribute as $index_att=>$val_att)
								{
								    $off_set_att=$index_att.$q;
									if(array_key_exists($off_set_att,$att_arr)):
										$super_attribute_arr[$index_att]=$att_arr[$off_set_att];
										$off_set_index=$q;
									else :
										$off_set_index=0;
									endif;		
												
								}
								if($off_set_index!=0) :	
								$params = array(
											'product' => $product_id,
											'super_attribute' => $super_attribute_arr,
											'qty' => 1,					
											);	
								$cart->addProduct($p, $params);	
								endif;	
							}							
							
						} 
						catch (Exception $e) 
						{ 
							continue; 
						}						
					} 
				$cart->save(); 
				Mage::getSingleton('checkout/session')->setCartWasUpdated(true);	
				if ($this->getRequest()->isXmlHttpRequest()) 
					{ exit('1'); } 
				$this->_redirect('checkout/cart');
		}   
}
