Skip to main content
added 217 characters in body
Source Link
Jigs Parmar
  • 2.4k
  • 2
  • 15
  • 33

use below code to add product to cart

   try
{

    $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);
}catch (Exception $e)
{
     Mage::log($e->getMessage());
}

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); 

use below code to add product to cart

   try
{

    $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);
}catch (Exception $e)
{
     Mage::log($e->getMessage());
}
Source Link
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);