Get the number of items in the cart via javascript - Ecommerce - Ecommerce - Progress Community

Get the number of items in the cart via javascript

 Ecommerce

Get the number of items in the cart via javascript

  • Get the number of items in the cart via javascript
  • 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
  • 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
  • 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
  • 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
  • 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