I have a plugin and i want to add a product to the actual cart. This is my code:
$productId = 2;
$params = array(
'form_key' => $this->formKey->getFormKey(),
'product' => $productId, //product Id
'qty' =>1 //quantity of product
'price' => 0
);
$_product = $this->product->load($productId);
$cart->addProduct($_product, $params);
$cart->save();
and i get the error: invalid request for adding product to quote. I try this:
$productId = 2;
$params = array(
'form_key' => $this->formKey->getFormKey(),
'product' => $productId, //product Id
'qty' =>1, //quantity of product
'price' => 0
);
//Load the product based on productID
$request = new Varien_Object();
$request->setData($params);
$_product = $this->product->load($productId);
$cart->addProduct($_product, $params);
$cart->save();
But it crash without any error.
Can someone help me to add a product to cart?
Thank you in advance!