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

Forums / Ecommerce / How to add to cart programmatically?

How to add to cart programmatically?

7 posts, 0 answered
  1. Lev Rosenblit
    Lev Rosenblit avatar
    37 posts
    Registered:
    14 May 2008
    01 Oct 2011
    Link to this post
    Hi,
    Can someone please tell me how can i get the cart_order_id of the logged in user?

    I  saw the logic used for the widgets has "GetShoppingCartForUser" method. how does this work?
    is the cart_order_id generated from the user_id somehow? is the mapping saved someplace in the db (i didnt find it)?
    or, is there another way to add to cart programmatically?

    Thanks,
    Lev Rosenblit

  2. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    02 Oct 2011
    Link to this post
    Hey Lev,

    Initially the shopping is strictly handled as 'cart', once you move into the checkout process the 'order' bits come into play. 

    The 'cart' is (on beginning) not tied to or based on any user, but is session based.  
    You can try this yourself with a browser which isn't logged in. You can add stuff to your shoppingcart,but as soon as you hit checkout, it asks for a login. 

    A cart id is created and stored as a cookie (see screenshot 1) as soon as you add something to the shoppingcart.

    This shoppingCardId cookie is the GUID referenced in the tables. In [sf_ec_cart_order] its the [id] field and all the subsequent cart tables reference it by the [cart_order_id]. (see screenshot 2)

    In the 3rd screenshot you can see a SQL diagram how they connect to each other. 
    (relationship/referential integrity are strictly to highlight the fields)

    As far as I know, the shoppingCardId cookie is strictly a random GUID.

    Jochem.
  3. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    05 Oct 2011
    Link to this post
    Hi Jochem,

    Thank you for your extensive explanation. It was really helpful. I hope Lev got the answer for his question. As a token of appreciation we updated your telerik points.

    Kind regards,
    Lubomir Velkov
    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
  4. Surbhi
    Surbhi avatar
    4 posts
    Registered:
    23 May 2012
    17 Oct 2012
    Link to this post
    Hi Jochem,
    Your explanation for the shopping cart was very helpful. I am trying to get the cart details on some custom page which appears after continue as guest/Login page. The flow is
    Click on checkout button - checks if user is logged and checks on product type. If it has type1 then redirect to some custom page with cart details for that particular product.

    Does that make sense? Am I clear what I am trying to say?

    Provide some inputs to this problem.

    Thanks,
    Surbhi
  5. Patrick Dunn
    Patrick Dunn avatar
    237 posts
    Registered:
    03 Nov 2014
    22 Oct 2012
    Link to this post
    Hi,

     Your best bet is to store the information you need as a session variable or in a cookie to persist between post backs. In your external page reference the Sitefinity classes and that will expose the API. For that see this article on eCommerce.

    Greetings,
    Patrick Dunn
    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
  6. Surbhi
    Surbhi avatar
    4 posts
    Registered:
    23 May 2012
    23 Oct 2012 in reply to Patrick Dunn
    Link to this post
    Hi Patrick,
    Thanks for the information. I was able to get all cart details on my custom page. What I did was get the shopping cart ID based on cookies and get the details of that shopping cart.

    Thanks,
    Surbhi
  7. Patrick Dunn
    Patrick Dunn avatar
    237 posts
    Registered:
    03 Nov 2014
    26 Oct 2012
    Link to this post
    Hello,

     Glad to hear. Let me know if you have any additional questions!

    Greetings,
    Patrick Dunn
    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
7 posts, 0 answered