Get the number of items in the cart via javascript

Posted by Community Admin on 05-Aug-2018 13:36

Get the number of items in the cart via javascript

All Replies

Posted by Community Admin on 14-Dec-2012 00:00

Hi,

We are creating a mobile website and in the navigation there is a cart item which is suppose to have an indicator of how many items are in the cart. Because this is part of the navigation and not a "cart summary" widget or anything like that I am wondering if there is a way I can get the number of items in the cart via javascript somehow and assign it to a element in the nav. 

Any other ideas if that's not possible?

The main problem is that the Add to cart does a ajax request so I also need to increase the number when that happens.

Seth

Posted by Community Admin on 19-Dec-2012 00:00

Hello Seth,

Make an Ajax call to ~/Sitefinity/Public/Services/Ecommerce/Order/CartOrder.svc
It will return a CartOrder and you can get the count from that.


Kind regards,
Randy Hodge
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 19-Dec-2012 00:00

Hi,

Thanks for that.

Do i need to have a orderid or guid or something? If so where do I get this from for the requesting user?... or will that return it for the current user automatically?

Do i need to authenticate, if so how?

Any samples will be appreciated.

Thanks for your help,
Seth

Posted by Community Admin on 21-Dec-2012 00:00

Hi,

This site is live now, I really need an answer to this so I can get this feature working:

www.mrrental.com.au/mobile

seth

Posted by Community Admin on 23-Dec-2012 00:00

Hello Seth,

You would need ShoppingCartId to make a request to the service. ShoppingCartId is generally stored in a cookie on the browser, reading it via Javascript should be trivial (You can follow a stack overflow post to do so here stackoverflow.com/.../javascript-getcookie-functions). You do not need to authenticate to get access to this service. Any services under ~/Sitefinity/Public are supposed to be public services and don't need authentication.


Thanks

Venkata Koppaka

This thread is closed