Developer forum

Forum » Ecommerce - Standard features » Discount per total number of units in an order

Discount per total number of units in an order

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Guys,

I have a project where I have to set a discount if the order contains a total number of items of the same product.

The product in question has some Orderline fields that makes possible to personalize each instance of the product.

For this reason, the product can be on separate orderlines on the same order.

What I need to do, is set up a discount if the order has a minimum number of x units of this product.
So far, I could manage to apply the discount only if there are x number of units on the same orderline but not on the whole order.

Any idea how I should set this up?

Thank you,

Adrian


Replies

 
Nicolai Pedersen
Reply

Custom orderdiscount is my best bet...

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

That was my bet as well. I just wanted to make sure I don't miss a combination of settings.

Thank you,

Adrian

 
Jens Mouritzen
Jens Mouritzen
Reply

Did you manage to do this Adrian ? I would sure like to see it. I need something likes this, i think.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Jens,

Not yet. We have tabled it for the moment until we fix other things. We gonna need to create a custom discount provider for that and we need to assign some hours for it.

I don't have a time estimate yet.
I can let you know after we finish it.

Thank you,
Adrian

 
Rui Silva
Reply

Hi guys,

You will need to build a custom SalesDiscountProvider with 2 parameters:

        [AddInParameter("Products")]
        [AddInParameterEditor(typeof(Dynamicweb.Ecommerce.Extensibility.Editors.ProductsAndGroupsEditor),
            "NewGUI=true")]
        public string ProductsAndGroupsParameter
        {
            get => _productsAndGroupsToOffer.ToString();
            set => _productsAndGroupsToOffer.ParseData(value);
        }

        [AddInParameter("Min Quantity")]
        [AddInParameterEditor(typeof(IntegerNumberParameterEditor), "NewGUI=true")]
        public int MinQuantity { get; set; }

 

And a override...

        public override void ProcessOrder(Order order)
        {
            if (_productsAndGroupsToOffer.IsEmpty() || MinQuantity <= 0)
            {
                return;
            }

            var orderLinesToOffer =
                order.ProductOrderLines.Where(ol => _productsAndGroupsToOffer.IsProductIncluded(ol.Product)).ToList();

            var productCount = orderLinesToOffer.Sum(ol => ol.Quantity);

            if (productCount < MinQuantity)
            {
                return;
            }

            DiscountValue.Amount = orderLinesToOffer.Sum(ol => ol.Price.Price);

            order.OrderLines.Add(CreateAmountOrderline(order, DiscountValue.Amount, false));
        }

 

 

 
Nicolai Pedersen
Reply

Hi Rui

Thanks for sharing!

BR Nicolai

 

You must be logged in to post in the forum