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

Add To Basket

2 posts, 0 answered
  1. Henriette
    Henriette avatar
    41 posts
    Registered:
    20 Aug 2009
    24 May 2013
    Link to this post
    Hi all

    We are currently trying to add some products to the ecommerce basket, but the item is never added. We are using the below code, but we think we are doing something wrong with the optionsDetails, but we cannot find any documentation of what that is. Can anyone help us out here :-)
    Kind regards
    Henrik

    Dim CatalogManager As New Telerik.Sitefinity.Modules.Ecommerce.Catalog.CatalogManager
           Dim _ordersManager As OrdersManager = OrdersManager.GetManager
     
           Dim ProductId As Guid = New Guid("86f2f2a8-b6bf-6704-817c-ff0000a02c2d") 'a simpel id of one of the products
     
           Dim Product As Telerik.Sitefinity.Ecommerce.Catalog.Model.Product = CatalogManager.GetProduct(ProductId) ' Get the right product
           Product.Description = CurrentCase.Titel
     
           Dim _OptionsDetails As New Telerik.Sitefinity.Ecommerce.Catalog.Model.OptionsDetails
     
     
           Dim _httpcookie As HttpCookie = Request.Cookies.Get(GetShoopingCartId.ToString)
     
           'Check if shopping cart cookie exists in the current request.
           If _httpcookie Is Nothing Then ' The Shoppingcart cookie does NOT exists
     
               Dim cartItem As CartOrder = _ordersManager.CreateCartOrder() ' create a new cart order
               Dim shoppingcartid = cartItem.Id 'that id is equal to the cookie value
               Dim Cookie As HttpCookie = New HttpCookie(shoppingcartid.ToString) '  create a new shopping cart cookie
               Dim now As DateTime = DateTime.Now
     
               'Set the cookie value.
               Cookie.Value = shoppingcartid.ToString()
               Cookie.Expires = now.AddYears(1) 'Set the cookie expiration date.
               Response.Cookies.Add(Cookie) 'Add the cookie.
               cartItem.Currency = "DKK"  'give cart item currency of DKK because it cannot be null
               _ordersManager.AddToCart(cartItem, Product, _OptionsDetails, 1) ''add the product to the cart
               _ordersManager.SaveChanges() 'save all changes
     
           Else 'The Shoppingcart cookie does exists
     
               Dim shoppingcartid As Guid = GetShoopingCartId()
     
               Dim _Cookie As HttpCookie = New HttpCookie(shoppingcartid.ToString) '  create a new shopping cart cookie
               Dim _guid As Guid = New Guid(_Cookie.Value.ToString()) ' get the cookie value as the guid
     
               Dim cartItem As CartOrder = _ordersManager.GetCartOrder(_guid) ' get the cart based on the cookie value
               _ordersManager.AddToCart(cartItem, Product, _OptionsDetails, 1) ' add the item to the cart
               _ordersManager.SaveChanges() ' save changes
     
           End If

  2. Henriette
    Henriette avatar
    41 posts
    Registered:
    20 Aug 2009
    24 May 2013 in reply to Henriette
    Link to this post
    Hi All

    We think that we got it. We were missing the CatalogManager.SaveChanges
    Thanks
2 posts, 0 answered