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

Forums / Developing with Sitefinity / Reading added items from shopping cart

Reading added items from shopping cart

6 posts, 0 answered
  1. Kiran
    Kiran avatar
    6 posts
    Registered:
    13 Jun 2014
    23 Jul 2014
    Link to this post

    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

  2. Bobby
    Bobby avatar
    10 posts
    Registered:
    22 Nov 2016
    24 Jul 2014
    Link to this post
    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();

    Code for GetShoppingCartId() :

    /// <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);
    }

    For more information regarding your ticket, you can check the following documentation.

    Feel free to contact us again if you have any other question. 

    Regards,
    Bobby
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Kiran
    Kiran avatar
    6 posts
    Registered:
    13 Jun 2014
    24 Jul 2014 in reply to Bobby
    Link to this post

    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

  4. Bobby
    Bobby avatar
    10 posts
    Registered:
    22 Nov 2016
    24 Jul 2014
    Link to this post
    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
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  5. Kiran
    Kiran avatar
    6 posts
    Registered:
    13 Jun 2014
    24 Jul 2014 in reply to Bobby
    Link to this post

    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

  6. Bobby
    Bobby avatar
    10 posts
    Registered:
    22 Nov 2016
    29 Jul 2014
    Link to this post
    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
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
6 posts, 0 answered