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.
 $productId = '2'; //should be dynamic or static depending upon your requirement.
 $cart = Mage::getModel('checkout/cart');
 $productCollection = Mage::getModel('catalog/product')->load($productId);
 $cart->addProduct($productCollection , array( 'product_id' => $productId, 'qty' => 1,'options' => array( $optionId => $optionValue));

Leave a Reply