cancel
Showing results for 
Search instead for 
Did you mean: 

How Magento manages a Guest Cart

How Magento manages a Guest Cart

Hello all,

I have a app wrote in react making api calls to magento Api.
The app uses the magento api to add a product inside a cart AS A GUEST.

The problem is, after I add a product using my app and then go to Magento cart PAGE and the product is not there.
I Believe that magento creates the guest cart when I add a product on the cart using MAGENTO site and then saves the cart in the database/cookie/session so when the user try to add a second item or access the cart page he already know that user has a cart.

 

I Would like to have the same behavior on my APP, I would like to add the products to a guest cart using the API, then when I go to magento cart it shows the items.

 

I really lost on how to solve it, can you help me?

Thanks!

4 REPLIES 4

Re: How Magento manages a Guest Cart

Hello bruno_soares

Magento use quotes table for maintenance guest and login user cart.  First, when any customer open app, you need create sessionId after that customer first time  add product in cart, you need  create quoteId( 'cart.create') and second time you need use same quoteId for maintenance multiple product in cart.

 

$sessionId = $proxy->login('apiUser', 'apiKey');
$quoteId = $proxy->call( $sessionId, 'cart.create', array( 'magento_store' ) );

 

 

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');

$quoteId = $proxy->call( $sessionId, 'cart.create', array( 'magento_store' ) );
$arrProducts = array(
	array(
		"product_id" => "1",
		"qty" => 2
                "options" => array(         
                    optionId_1 => optionValue_1,
                    ...,
                    optionId_n => optionValue_n
                 )
	),
	array(
		"sku" => "testSKU",
		"quantity" => 4
	)
);
$resultCartProductAdd = $proxy->call(
	$sessionId,
	"cart_product.add",
	array(
		$quoteId,
		$arrProducts
	)
);


Please find below soap and reset api links of magento.

Url:https://devdocs.magento.com/guides/m1x/api/soap/checkout/cartProduct/cart_product.add.html

Hope it will help to solve problem then please click Accept as Solution!"

 

 

Re: How Magento manages a Guest Cart

Thank you for the reply.
I still have some questions.
In my scenario I m trying to add a product to the cart as Guest, so how can I create a session? I see that the method login receives 2 parameters but if I am a guest/anonymous user I wont have a username and password right?

Another thing that I forgot to mention is that Im using Magento 2.

Re: How Magento manages a Guest Cart

 

Hello bruno_soares

 

First of all, Magento provide soap and reset api with help we can performa and get all functiona like normal magento frontend. We can get product list,categlory list, customer list and place order and and many more. Kindly find below api list.

URL: https://devdocs.magento.com/guides/v2.0/rest/list.html

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');

This is not customer login, Its apiUser and apiKey which you can create from admin. Kindly below video how to create api user.

https://www.youtube.com/watch?v=3s1WtEDPQuQ
https://www.youtube.com/watch?v=hMN-ZoeODlQ

if you are looking hybrid app then look below ionic framework.

Url:https://www.ipragmatech.com/magento2-mobile-app-using-ionic-framework/

Hope it will help to solve problem then please click Accept as Solution!"

Re: How Magento manages a Guest Cart

Hello prakash123321,

 

Got it!

 

What I have done is,

 

1 - Created the integration token

2 - I'm using it to call the endpoints to Create Cart/Add product to the cart

3- Copy the phpsessionID that postman returns

4- Go to magento website, change phpsession id by the one that I got from postman

5- Refresh the page...

6- And.. Magento doesn't retrieve the "guestcart" based on session.

 

Am I missing something?

 

Thank you!