Developer forum

Forum » Development » SalesDiscountProvider DW8

SalesDiscountProvider DW8

Jacob Søndergaard
Reply

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

 

 

 


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Jacob

 

Remember to create a discount in management center, ecommerce, product catalog, sales discount. Choose your provider when creating a new. It should show up in the list there.

 

BR Nicolai

 
Jacob Søndergaard
Reply

Hi Nicolai

 

Perfect, just what it needed - Thank you :)

 

 

 

Best Regards

 

Jacob Søndergaard

 

You must be logged in to post in the forum