Oct 22, 2014

Posted by in Magento, Technology | 0 comments

Add configurable product to cart programatically in Magento

We often come up with situation where we need to add prducts to cart programatically in Magento. You can use the following code to achive this.
<?php
 $productId = '2'; //should be dynamic or static depending upon your requirement.
 $cart = Mage::getModel('checkout/cart');
 $cart->init();
 $productCollection = Mage::getModel('catalog/product')->load($productId);
 $cart->addProduct($productCollection , array( 'product_id' => $productId, 'qty' => 1,'options' => array( $optionId => $optionValue));
 $cart->save();
?>

Leave a Reply