How to add product in a cart with Logged In user SOAP API magento?

hey, i am working on magento api and i want to add products from android and the added products should show in my account but its not showing any product which i have added i dont know whats the problem i think its session issue can please anyone see in this matter thanks.

Add Comment
1 Answer(s)

hey, you can use this code i am using this code and its working fine for me and adding products in my account



       $session = Mage::getSingleton(“core/session”, array(“name” => “frontend”));

       $user = $_REQUEST[‘user’];

       $pass = $_REQUEST[‘pass’];

//load product which is passed in query string

       $product = Mage::getModel(‘catalog/product’)->load($_REQUEST[‘product_id’]);

       Mage::getSingleton(“core/session”, array(“name” => “frontend”));

            //getting website id  

       $websiteId = Mage::app()->getWebsite()->getId();

//getting store id

       $store = Mage::app()->getStore();

//getting customer

       $customer = Mage::getModel(“customer/customer”);

//assigning customer website id

       $customer->website_id = $websiteId;

 //assigning customer store id


//loading customer by mail id


 // flag to check if customer is logged in or not



// logging in a customer and starting a session  

                    $session = Mage::getSingleton(‘customer/session’)


// login user

        $session->login($user, $pass);


$quote = Mage::getModel(‘sales/quote’)->loadByCustomer($customer);

// set store id



$stockProduct = Mage::getModel(‘cataloginventory/stock_item’)


  $productActualQty = $stockProduct->getQty();

   $data[‘cart_total’] = getCartItemcount();



     $quote = Mage::getSingleton(‘checkout/session’)->getQuote();

     $_item = $quote ? $quote->getItemByProduct($product) : false;

     $cartItemQty = $_item ? $_item->getQty() : 0;

     $remaningQty=$productActualQty – $cartItemQty;

     if($remaningQty > 0 )


    if (isset($_REQUEST[‘opt_value’])) {

            $options = array();

foreach($_REQUEST[‘opt_value’] as $attribute_code => $option){

$attributeId =      Mage::getResourceModel(‘eav/entity_attribute’)

->getIdByCode(‘catalog_product’, $attribute_code);       $options[$attributeId]= $option;


$params = array(

“product_id” => $product->getId(),

“qty” => $_REQUEST[‘qty’],

“super_attribute” => $options


} else {

$params = array(

“product_id” => $product->getId(),

“qty” => $_REQUEST[‘qty’]



$quote = Mage::getSingleton(‘checkout/cart’)->init();

$quote->addProduct($product, $params);




echo json_encode($data);


Else {

$data[‘status’]=’Out Of stock’;

echo json_encode($data);



// add product and its qty



$data[‘status’]=’Out Of stock’;

echo json_encode($data);


// save



} catch( Exception $e ) {


if(!Mage::getSingleton(‘customer/session’)->isLoggedIn()) {


echo json_encode ($data);



Answered on June 18, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.