Skip to main content
1 of 2
Jigs Parmar
  • 2.4k
  • 2
  • 15
  • 33

use below code to add product to cart

 $cart = Mage::getSingleton('checkout/cart');
    $cart->init();
    
    $qty=1;
    
    $productId='10'; //product id
    
    $product = Mage::getModel('catalog/product')->load($productId);
    $formKey = Mage::getSingleton('core/session')->getFormKey();
    
    if($product->getSku()!='')
    {
        $paramater = array(
            'product' => $productId,
            'qty' => $qty,
            'form_key' => $formKey
        );
        
        $cart->addProduct($product, $paramater);
        $cart->save();
    }
    else
    {
        Mage::log('product not vailable');  
    }
    $cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true); 
Jigs Parmar
  • 2.4k
  • 2
  • 15
  • 33