How To Add Magento Product To Cart Programmatically

How can I add a Magento product to current cart programmatically

You need to use checkout/cart and catalog/product models to add Magento product to the current cart

$cart = Mage::getSingleton('checkout/cart');
$cart->init();
$options = array('1'=>'3','2'=>'6'); // product options
$product = Mage::getModel('catalog/product')->load(2); // product id - 2

$paramater = array('product' => '2', // product id - 2
    'qty' => '1',
    'form_key' => Mage::getSingleton('core/session')->getFormKey(),
    'options' => $options 
);       

$request = new Varien_Object();
$request->setData($paramater);
$cart->addProduct($product, $request);
$cart->save();

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments