i have written a small functionality, where i need to get data from XML or CSV and populate the data in the cart.
I am able to read the data from the file and create an array of the items
foreach ($products as $productId => $singleQty)
{
$product = $this->productModel->load($productId);
if ($product)
{
echo $product->getId() .'<br/>';
$this->cart->addProduct($_product, array('qty' => $singleQty));
$this->cart->save();
}
}
the echo result is completely fine, it displays the product Ids correctly
But only one item gets added into the cart, with the total number of items.
Suppose i have product IDs 2 and 4 with quantities 200 and 400 respectively,
the above snippet only adds product with ID 2, but the quantity added is 600
Any idea what i am doing wrong?