Developer forum

Forum » Development » Create Basket?

Create Basket?

Jais Edelmann
Reply
When the basket is empty the cart object is null.

I need to add a product via
Dynamicweb.eCommerce.Common.Context.Cart.Products.Add(_p);
How will i go about creating the cart? i've not been able to see how you guys do in reflector (running 18.x.x.x version)

Replies

 
Nicolai Høeg Pedersen
Reply
If nothing have been added to the cart yet, you have to create a new instance:
If Context.Cart Is Nothing Then
      Context.SetCart(New Order() With {.IsCart = True, .LanguageID = Common.Context.LanguageID})
      Context.Cart.Save()
End If
Then you can use Dynamicweb.eCommerce.Common.Context.Cart.Products.Add...

Pageview should be accessed using pageview.current - and it is not session based but stored in HttpContext.Current.Items.

 
Jais Edelmann
Reply
    if (Dynamicweb.eCommerce.Common.Context.Cart == null)
                {
                    Order _o = new Order();
                    _o.IsCart = true;
                    _o.LanguageID = Dynamicweb.eCommerce.Common.Context.LanguageID;

                    Dynamicweb.eCommerce.Common.Context.set_Cart2(_o, _o);
                    Dynamicweb.eCommerce.Common.Context.Cart.Save();
                }


                Dynamicweb.eCommerce.Products.Product _p = new Dynamicweb.eCommerce.Products.Product(ProductID);
                Dynamicweb.eCommerce.Common.Context.Cart.Products.Add(_p);
                Dynamicweb.eCommerce.Common.Context.Cart.Save();

Im unable to see the method SetCart on Context, however i can see a method called set_Cart2 which takes 2 parameters Order initcard and order value.
 
I've trieede using this method instead and i dont get an cart exception but it doesent reflect on the site.
 
 
Nicolai Høeg Pedersen
Reply
Maybe it is because of your 18.* something branch? That is VERY old...

This is for DW 7:
http://developer.dynamicweb-cms.com/api/ecommerce/?Dynamicweb~Dynamicweb.eCommerce.Common.Context~SetCart.html


This is what happens inside SetCart:
HttpContext.Current.Session("EcomCart") = cart
CartCatch.SaveCart()

 

You must be logged in to post in the forum