Hi
We have made a function that allows customers to add free products to the shopping cart.
The Sales Discount module allows to add a free product to selected products. We are not able to use that function because our customer wants to let their customers choose witch variant they want to add. For example: A customer bought a red XL size product, won't be happy with a free blue S size product.
The code we made to add free products works:
Protected Sub AddDiscount(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim myOrder As eCommerce.Orders.Order = DirectCast(Session("EcomCart"), eCommerce.Orders.Order)
Dim myOl As eCommerce.Orders.OrderLine = eCommerce.Orders.OrderLine.Create(e.CommandArgument.ToString)
Dim btnToevoegen As Button = CType(sender, Button)
Dim ddlVarianten As DropDownList = CType(btnToevoegen.Parent.FindControl("ddlVarianten"), DropDownList)
Dim sVariantID As String = ddlVarianten.SelectedItem.Value
Dim sVariantName As String = ddlVarianten.SelectedItem.Text
Dim myFreeProduct As eCommerce.Products.Product = eCommerce.Products.Product.Create(e.CommandName, sVariantID)
Dim ol As New Dynamicweb.eCommerce.Orders.OrderLine(myFreeProduct)
ol.Order = myOrder
ol.Quantity = myOl.Quantity
ol.ProductName = myFreeProduct.Name & " * " & GetTranslation("Gratis", sCulture) & " *"
ol.ProductVariantID = myFreeProduct.VariantID
ol.ProductVariantText = sVariantName
ol.SetUnitPrice(Convert.ToDouble(0))
ol.Reference = myOl.ID.ToString
ol.Type = Dynamicweb.Base.ChkNumber(Dynamicweb.eCommerce.Orders.OrderLine.OrderLineType.Fixed).ToString()
ol.DiscountID = sDiscountID
myOrder.OrderLines.Add(ol, False)
myOrder.Save()
Response.Redirect(Request.RawUrl)
End Sub
The only problem is when the shop also has a salesdiscount like a discount with percentage.
That discount also invokes the free products in the cart of the customer, but calculates the discount on the original productprice.
So the customer gets a free product, andalso extra discount.
I've tried to add the free product on different ways, in stead of the orderlinetype 'fixed', with the type 'discount' and 'productdiscount'. With that types I can see that the free product is added to the database, but with a pageload it's already removed from the cart. (Probably because the properties don't match with the discountproperties).
Is there a way to tell a Sales Discount not to add the discount on an orderline with orderlinetype 2 (fixed)?
Or is there an other solution to add free products, witch let's customers choose there variant?