I'm adding a nominal product programically to the shopping cart. But it throws an exception as 'The stock item for Product is not valid.'
. How can I resolve this?
NOTE : $product
is getting passed to this function correctly.
My code is as follows.
/**
* Add air product to the cart.
*/
public function addSubscriptionToCart($product)
{
try {
// Create cart instance.
$cart = Mage::getModel('checkout/cart');
// Initialize the cart.
$cart->init();
$cart->addProduct($product, array('product_id' => $product->getId(), 'qty' => 1)); // This line causes the error.
$cart->save();
return true;
} catch(Exception $e) {
Mage::log($e->getMessage());
return false;
}
}