+1-888-365-2779
Try Now
More in this section

Forums / Ecommerce / Get the number of items in the cart via javascript

Get the number of items in the cart via javascript

5 posts, 0 answered
  1. UI Crew
    UI Crew avatar
    151 posts
    Registered:
    27 Sep 2012
    14 Dec 2012
    Link to this post
    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
  2. Randy Hodge
    Randy Hodge avatar
    96 posts
    Registered:
    03 Nov 2014
    19 Dec 2012
    Link to this post
    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
  3. UI Crew
    UI Crew avatar
    151 posts
    Registered:
    27 Sep 2012
    19 Dec 2012 in reply to Randy Hodge
    Link to this post
    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
  4. UI Crew
    UI Crew avatar
    151 posts
    Registered:
    27 Sep 2012
    21 Dec 2012 in reply to Randy Hodge
    Link to this post
    Hi,

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

    http://www.mrrental.com.au/mobile

    seth
  5. Venkata
    Venkata avatar
    14 posts
    Registered:
    14 Aug 2009
    23 Dec 2012
    Link to this post

    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 http://stackoverflow.com/questions/4003823/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

5 posts, 0 answered