Developer forum

Forum » Development » Custom product discount provider

Custom product discount provider

Mikkel Ulstrup
Reply

Hi,

I am looking for a way to handle product discounts based on custom functionality. I want the discount to be rendered in the productlist, product details and in the cart.

When I use standard salesdiscounts and choose product discount, the price gets rendered for each product in the productlist without having products ni the cart. But when I create my own SalesDiscountProvider, this is not the case - It only hits this custom provider, when I have products in the cart.

How can I achieve this functionality? - Any recommendation regarding extenders or providers?

The SalesDiscountProvider only have ProcessOrder(Order order) - probably because it is an order discount, but the standard feature seems to support product discounts. Can I somehow use this for handling product discounts?

I have tried this with no success - the "ProccessOrder" does not get hit without products in the cart:

http://doc.dynamicweb.com/forum/development/custom-productdiscount?PID=1605

I am using DW 8.9

 

Kind regards

Mikkel Ulstrup


Replies

 
Nicolai Pedersen
Reply

Hi Mikkel

Yes, there is a difference. Try inheriting ProductDiscount instead of SalesDiscountProvider directly.

BR Nicolai

 
Mikkel Ulstrup
Reply

Hi Nicolaj,

I allready did that. The Provider shows up in the administration:
https://www.screencast.com/t/Fi7K4Cl6zQWc

I do not wish to ude the Red area, since the discount is unique to for each product.

I have chosen "All products" in the Yellow area, and then i want to select specific products in my custom code.

 

If I choose a percentage in the red area, the discount gets applied (the default discount), but how can I control this myself?

Should I use another provider og extender for this functionality?

 

Kind Regards

Mikkel Ulstrup

 
Nicolai Pedersen
Reply

Hi Mikkel

It sounds like the right approach...

If you want the discount to show up as a discount, this is the way to go. An alternative is the priceprovider, but that will change the price, and not appear as a discount in the cart.

Can I see your code?

BR Nicolai

 
Mikkel Ulstrup
Reply

Hi again,

I need it to show up as a  discount, so the priceprovider is not an option.

 

No functionality so far... It just don't hit this. So where can I put my logic?

 

[AddInName("SpNavDiscountCodeProvider"), AddInDescription("Discount provider for discount codes from NAV"),
    AddInActive(true), AddInIsAdditional(false)]
    public class SpNavDiscountCodeProvider : ProductDiscount
    {
        public override void ProcessOrder(Order order)
        {
            switch (DiscountValue.Type)
            {
                case DiscountTypes.FixedAmount:
                    //TODO: Add code here
                    break;
                case DiscountTypes.Percent:
                    //TODO: Add code here
                    break;
                case DiscountTypes.Products:
                    //TODO: Add code here
                    break;
                case DiscountTypes.Unknown:
                    //TODO: Add code here
                    break;
            }
        }

    }

 
Nicolai Pedersen
Reply

So if you compile this, set it up for all products, set the amount to i.e. 1 for every currency, it never gets executed?

 
Mikkel Ulstrup
Reply

The discount of 1 DKK for all products get rendered.

If I have products in the cart, the "ProcessOrder" get hit (when I add products to the cart and when loading the cart).

 

But I do not want 1 DKK for all products. I want to control the specific products dynamically and the discount amount uniquely for each product when loading the productlist regardless of the state of the cart.

 

- Mikkel

 
Nicolai Pedersen
Reply

Hi Mikkel

Yes - now I understand!

I am affraid that is not possible with the current implementation. I cannot think of a workaround right now...

But I understand what you are trying to do, but we do not have a hook for it.

BR Nicolai

 
Umar Farooq
Reply

Hi Nicolai,

Is  there any solution for this or a workaround? As I have a similar scenario where would like to exclude some of the products from the discount. I have made a logic to exclude products from orderline on which discount should not be applied by inheriting SalesDiscountProvider but how to handle this on Product List and Product detail ?

 

BR Umar 

 
Nicolai Pedersen
Reply

Hi Umar

No, there is not. It sounds like that you can use a template extender to do some magic?

 

You must be logged in to post in the forum