Programmatically add product to cart (by ID)

Submitted by metaharper - 5 years ago

I used this outside of Magento but it can be used in PHTML files as well I believe.

$id = '226'; // Replace id with your product id
$qty = '1'; // Replace qty with your qty
$_product = Mage::getModel('catalog/product')->load($id);
$cart = Mage::getModel('checkout/cart');
$cart->addProduct($_product, array('qty' => $qty));
Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean