Developer forum

Forum » Development » Create cart with discount codebehind

Create cart with discount codebehind

Martijn Bokhove
Reply

Hi

 

For our customer we are trying to create a cart with discount codebehind.

We recieve a list with products from another solution and try to create a cart with it.

 

It works with the samplecode below:

 

Dim newOrder As Order = Order.Create("")
        newOrder.ShopID = "SHOP1"
        newOrder.LanguageID = "LANG1"
        newOrder.DowngradeToCart()

        Dim newProd As Product = Product.Create("PROD2652")
        Dim ol As New Dynamicweb.eCommerce.Orders.OrderLine(newProd)
        ol.Order = newOrder
        ol.Quantity = 1
        ol.Product = newProd
        ol.SetUnitPrice(newProd.Price.Price)
        ol.Type = Dynamicweb.Base.ChkNumber(Dynamicweb.eCommerce.Orders.OrderLine.OrderLineType.Product).ToString()
        newOrder.OrderLines.Add(ol, True)

        newOrder.Save()

 

The cart looks the same as when adding the product to the cart on the frontend.

The only difference is, that there is no discount added.

 

In this case we added a 10% discount on the complete order. Adding the product frontend creates the discount, adding the product codebehind does not add the discount.

 

Is there a function to call, so the discount will be added as well when adding the product codebehind?

 

Gr

Martijn


Replies

 
Morten Snedker
Reply

You have not assigned the Order object to the cart. Wrap it up with a

 

HttpContext.Current.Session["Cart"] = newOrder;

 

Regards /Snedker

 

 
Martijn Bokhove
Reply

Hi Morton

 

I have tried the code on several places, but all with no effect.

Also tried to add:

Dynamicweb.eCommerce.Frontend.Cart.CartCatch.SaveCart()

But that also did not make a difference.

 

Gr

Martijn

 

You must be logged in to post in the forum