Magento – Add product to cart programatically
Today I encountered a situation where I had to add a product to cart by code. Here is how I did it: $id = ‘1’; //Product Id $qty = ‘1’; //Quantity $_product = Mage::getModel(‘catalog/product’)->load($id); $cart = Mage::getModel(‘checkout/cart’); $cart->init(); $cart->addProduct($_product, array(‘qty’ => $qty)); $cart->save(); Mage::getSingleton(‘checkout/session’)->setCartWasUpdated(true);
Read More