0

I am adding a product to cart via SOAP V2 API:

$client = new SoapClient('http://mywebsite.com/api/v2_soap/?wsdl');
$session = $client->login('username', 'password');

$quoteId = $client->shoppingCartCreate($session);

$customerData = array(
    "firstname" => "Klevis",
    "lastname" => "Miho",
    "email" => "kmiho@myemail.com",
    "customer_id" => 2522,
    "mode" => "customer",
    "website_id" => "1"
);


$resultCustomerSet = $client->shoppingCartCustomerSet($session, $quoteId, $customerData);

$result = $client->shoppingCartProductAdd($session, $quoteId, array(array(
    'product_id' => '336',
    'sku' => '110757',
    'qty' => '1',
    'options' => null,
    'bundle_option' => null,
    'bundle_option_qty' => null,
    'links' => null
)));   

$result1 = $client->shoppingCartInfo($session, $quoteId); 

var_dump($result); //returns true

In the end it returns true. But when I login on the frontend there are no products in my shopping cart.

Am I missing something here?

2

The Magento SOAP API is a web-Service and is meant for data exchange with external systems such as ERP, accounting, etc. You can create orders via SOAP-API in your shop which you will see afterwards in the customers account as well as in the shop admin-interface.

The use-case you are trying to create is, to fill a customers shopping cart with products. So, basically, what you're doing is right, it's just not the way the intended usage of the web-service.

I've never set it up like this, but what you need to do to achieve your goal is, to create a connection between your visitors/customers session in the browser and the shopping cart.

Depending on your intended usage you'll need to access the visitors', customers' and checkout session:

Get the visitor session:

$session = Mage::getSingleton('core/session');

Get the customer session:

$session = Mage::getSingleton('customer/session');

Get the checkout session:

$session = Mage::getSingleton('checkout/session');

Set customers session to checkout session:

Mage::getSingleton('checkout/session')
    ->setCustomer(Mage::getSingleton('customer/session')->getCustomer());

Whatever you do: Be careful with setting, storing,... the session-id via URL and cookies. This can be a potentical security issue.

  • Someone is building a android app which just adds products on the cart, then the user can checkout from a desktop. I am testing the SOAP API for that. Makes sense? What do I need to add to make code to make it work? – Klevis Miho Sep 17 '14 at 11:06
  • I see. Persistant Shopping might also be a solution for you then?! magentocommerce.com/knowledge-base/entry/… – Anna Völkl Sep 17 '14 at 11:14
  • I have enabled Persistent Shopping cart, but doesn't solve the problem. Thanks Anna for trying to help me. – Klevis Miho Sep 17 '14 at 11:20
0

I think you have to set quote(shopping cart) active by custom code:

$quoteData = Mage::getModel('sales/quote')->load($quoteId);
if($quoteData->getIsActive()==0) {
  $quoteData->setIsActive(1)->save();
}

because by default quote is not activated when its created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.