Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3950478
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:36:59+00:00 2026-05-20T01:36:59+00:00

Writting custom script to add product to particular customer. In this way. $product =

  • 0

Writting custom script to add product to particular customer.

In this way.

                 $product = Mage::getModel('catalog/product')->load($id);

                $cart = Mage::getSingleton('checkout/cart');
                $cart->truncate();
                $cart->save();
                $cart->getItems()->clear()->save();                 
                $req = Mage::app()->getRequest(); 
                $request['qty'] = $selected_qty[$i]; 
                $request['product'] = $value;               

                $prod_req = new Varien_Object($request);                
                try {       
                    $cart->addProduct($product, $prod_req);
                    $cart->save();  
                    $msg .= "<p>".$product->getName(). " ==> ".$selected_qty[$i] . " items <br/></p>";                      
                }
                catch (Exception $ex) {
                    $err .= "<p>".$ex->getMessage(). " <br/></p>";;
                }

Customer session shows logged in customer details, but this doesn’t adding the product to the cart. Whats the problem, could anyone find out.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:36:59+00:00Added an answer on May 20, 2026 at 1:36 am

    I got it working by in the same way from inchoo site. Thanks to them.

    Here is what i have now.

    $product =   Mage::getModel('catalog/product')->load($value);                   
                    $cart    = Mage::getSingleton('checkout/cart');
    
                    $params = array(
                        'product' => $value,
                        'related_product' => null,                  
                        'qty' => $selected_qty[$i],
                    );      
    
                    try {       
                        $cart->addProduct($product, $params);
                        $cart->getItems()->save();               
                        Mage::getSingleton('checkout/session')->setCartWasUpdated(true);                
                        $msg .= "<p>".$product->getName(). " ==> ".$selected_qty[$i] . " item(s) <br/></p>";                        
                    }
                    catch (Exception $ex) {
                        $err .= "<p>".$ex->getMessage(). " <br/></p>";;
                    }   
    

    Its working perfectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writting my custom helper. I tried to use the language helper: $this->lang->line('site_title')
I am writing a custom .pac script for use with Firefox. Following numerous examples
I am writing a script that will look in a custom reports directory, copy
I'm writting a custom JSF component that will render image transitions for a set
I have written this short script (which I've stripped away some minor detail for
I'm writing a custom php code in my Drupal website. I need to load
I am writing a release script in powershell and need to invoke a custom
I'm writing a bulk insert script using Django's ORM + custom raw SQL. The
I am writing a custom JavaDoc Taglet, and want to load and create an
Writing an application for a custom gallery, and all the script files are put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.