I'm trying to add multiple variations of a configurable product to the cart at once, and I've put the code together, but currently it's adding the right qty of products, but only using the first variation.
In other words, if I try to add 2 Green T-Shirts and 4 White T-Shirts, it's adding 6 Green T-Shirts.
This is the code I've got:
public function indexAction () {
$post = $this->getRequest()->getPost();
$attr = array_keys($post['super_attribute']);
$cart = Mage::getSingleton('checkout/cart');
$product = Mage::getModel('catalog/product')->load($post['product']);
foreach ($post['super_attribute'][$attr[0]] as $optId){
if (abs($post['qty'][$optId]) > 0){
$options = array(
//"product"=>$post['product'],
"super_attribute"=>array(
$attr[0] => $optId
),
"qty"=>$post['qty'][$optId]
);
echo "Add To Cart:";
print_r($options);
echo "<br /><br />";
$cart->addProduct($product, $options);
}
}
$cart->save(); // save the cart
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
die("??");
$this->_redirect('checkout/cart/');
}
And from that print_r, it's confirming that the options are correct:
Add To Cart:Array ( [super_attribute] => Array ( [141] => 5 ) [qty] => 2 )
Add To Cart:Array ( [super_attribute] => Array ( [141] => 4 ) [qty] => 4 )
But in the cart I'm seeing 6 of the first super_attribute.
Is there something I need to do to 'reset' the cart after adding each item or something?
Thanks!