Reading added items from shopping cart
Hello,
I am using sitefinity shopping cart widget, i want to read the products added to shopping cart. I am not using check out. how can i read the added items to shopping cart. i want to read the added items to cart and store it in db.
Please let me know, how can i do this.
Thank you for your help!
Kiran
Hello Kiran,
Thank you for contacting Telerik Support.
You can get the products added to shopping cart by using the following code :
OrderManager manager = OrderManager.GetManager();
//get shopping cart for the current user, or by cookie.
var shoppingCart = manager.TryGetCartOrder(
this
.GetShoppingCartId());
var cartDetails = shoppingCart .Details();
/// <summary>
/// This method gets the id of the shopping cart for the current user.
/// </summary>
/// <remarks>
/// This method uses cookies as persistence for the shopping cart.
/// </remarks>
/// <param name="ordersControl">
/// The instance of <see cref="IOrdersControl"/> which this method extends.
/// </param>
/// <returns>
/// The id of the shopping cart; empty GUID if user has no shopping cart.
/// </returns>
public
static
Guid GetShoppingCartId()
HttpCookie shoppingCartCookie = SystemManager.CurrentHttpContext.Request.Cookies[EcommerceConstants.OrdersConstants.ShoppingCartIdCookieName];
if
(shoppingCartCookie ==
null
||
string
.IsNullOrWhiteSpace(shoppingCartCookie.Value))
return
Guid.Empty;
if
(!shoppingCartCookie.Value.IsGuid())
throw
new
InvalidOperationException(
"cartOrderId string cannot be parsed as a GUID; please provide a valid cartOrderId value."
);
return
new
Guid(shoppingCartCookie.Value);
public
static
Guid GetShoppingCartId(HttpCookie shoppingCartCookie)
if
(shoppingCartCookie ==
null
||
string
.IsNullOrWhiteSpace(shoppingCartCookie.Value))
return
Guid.Empty;
if
(!shoppingCartCookie.Value.IsGuid())
throw
new
InvalidOperationException(
"cartOrderId string cannot be parsed as a GUID; please provide a valid cartOrderId value."
);
return
new
Guid(shoppingCartCookie.Value);
Thanks Bobby for the reply.
I am new sitefinity, i am learning and developing. i created page templates for each page and added shopping cart to one the page templates. can you please tell me where can i add this custom code? do i need to create new controller or file under mvc folder? where do i put this code. Please help.
Thanks,
Kiran
Hello again Kiran,
Could you please bring more light of what you are trying to achieve? Would it be possible for you to provide key steps you are taking or any other information that may help us understand your task?
Regards,
Bobby
Telerik
Hi Bobby,
Here is the task:
I need to save the products added to the cart, get the customer contact information and save it to the sitefinity with products added to cart and contact information. Its like a quick shopping cart without using checkout module. is it possible ?
Thanks,
Kiran
Hi again Kiran,
You can check the following project, there you can find single page checkout and custom logic that may help you with your task, as almost every task you mentioned is done there.
Regards,
Bobby
Telerik