Я пытаюсь добавить в корзину сразу несколько вариантов настраиваемого продукта, и я собрал код вместе, но в настоящее время он добавляет нужное количество продуктов, но использует только первый вариант.
Другими словами, если я попытаюсь добавить 2 зеленые футболки и 4 белые футболки, я добавлю 6 зеленых футболок.
Вот код, который у меня есть:
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/');
}
И из этого print_r он подтверждает, что параметры верны:
Add To Cart:Array ( [super_attribute] => Array ( [141] => 5 ) [qty] => 2 )
Add To Cart:Array ( [super_attribute] => Array ( [141] => 4 ) [qty] => 4 )
Но в тележке я вижу 6 первых super_attribute.
Что мне нужно сделать, чтобы «сбросить» корзину после добавления каждого товара или чего-то еще?
Спасибо!