How to add to cart programmatically?
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
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.
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,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
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,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
Hello,
Glad to hear. Let me know if you have any additional questions!
Greetings,