Hi
I have this code example from the Dynamicweb DW8 documentation on the SalesDiscountProvider - but i cannot get Dynamicweb to recognize it. My PriceProvider in the same build is working/recognized perfectly.
Am I missing something?
using System;
using Dynamicweb.eCommerce.Orders;
using Dynamicweb.eCommerce.Orders.SalesDiscounts;
using Dynamicweb;
using Dynamicweb.Extensibility;
namespace EcreoApplication.Providers
{
[AddInName("Ecreo Discount"), AddInDescription("This discounts provides a 10% discount for customers with a .dk e-mail address.")]
public class EcreoSalesDiscountProvider : SalesDiscountProvider
{
public override void ProcessOrder(Order order)
{
if (DiscountValue.Type != DiscountTypes.Percent)
{
throw new NotImplementedException(@"Discounts for types other than Percent are not supported in this demo.");
}
double discountPercentage = 10d;
if (order.CustomerEmail.ToLower().EndsWith(".dk"))
{
double discountPrice = CalculateDiscountPrice(order, discountPercentage);
OrderLine line = CreateOrderLine(order, discountPrice);
order.OrderLines.Add(line);
}
}
private static double CalculateDiscountPrice
(Order order, double discountPercentage)
{
double discountPrice = (order.PriceBeforeFees.PriceWithoutVAT / 100)
* discountPercentage;
discountPrice = discountPrice * -1;
return discountPrice;
}
private OrderLine CreateOrderLine(Order order, double discountPrice)
{
OrderLine line = new OrderLine
{
Order = order,
Quantity = 1,
ProductName = DiscountName
};
line.SetUnitPrice(discountPrice);
line.Type = Base.ChkString(Base.ChkNumber(OrderLine.OrderLineType.Discount));
return line;
}
}
}
Best Regards
Jacob Søndergaard