Developer forum

Forum » Development » Use orderline instead of product on Discount Extender

Use orderline instead of product on Discount Extender

Mario Santos Dynamicweb Employee
Mario Santos
Reply

Hi,

The method DiscountValidForProduct from DiscountExtender receives the orderline product has a parameter. Although, this is not very helpfull because we can only access product information. I think it should have the orderline as a parameter instead, so we can access the orderline properties like quantity and order, and the product would be accessible too.

Thoughts?

BR, Mario


Replies

 
Nicolai Pedersen
Reply

DiscountValidForProduct is for product discounts and there is no order. Say, you have a product - and you show the product on the frontpage to a user coming right now without adding anything to the cart. The discount is "Black friday, 50% off". There is no order - there is only a product and this method is to decide wether the product should be shown with a discount or not.

If you want to look at the order, you need to look at the OrderDiscount and then the extender also has a DiscountValidForOrder method that takes an Order.

Voila.

 
Nicolai Pedersen
Reply

And if you choose to look at the order in DiscountValidForProduct which would be a mistake, you can go for common.context.cart - but I will not help you out of your misery when you do that :-)

 
Mario Santos Dynamicweb Employee
Mario Santos
Reply

Hi Nicolai,

I am not following when you say there is no order, the method DiscountValidForProduct is called with the Product property of the orderline, so there is an order (see attached image).

BR, Mario

 

 

 

CheckExtender.jpg
 
Nicolai Pedersen
Reply

Hi Mario

Read my first post. DiscountValidForProduct is called from lists of products - which are not in the cart.

BR Nicolai

 
Mario Santos Dynamicweb Employee
Mario Santos
Reply

Hi Nicolai,

I see your logic now. Although the same method is being used for products that are in the cart too when discount is set to apply as "Product discount" - see my previous post.
Maybe a different method for that?

BR, Mario

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have a potentially similar situation like the one described here by Mario, mainly, setting up a discount orderline based on some rules.

In my case, I have some custom values on some orderlinefields and based on the values of these fields, I have to decide if I apply an orderline discount or not.

In my case, I would rather keep the orderline discount attached to the parent orderline as I can have multiple orderlines with the same product.

How do I accomplish this request?

Thank you,
Adrian

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Create a discount extender by inheriting DiscountExtenderBase and implement IDiscountExtenderCalculateProductDiscount

Override DiscountValidForProduct from DiscountExtenderBase and in that method find the orderline fields in question and return true if the discount should be given.  Implement the GetDiscount from the IDiscountExtenderCalculateProductDiscount interface to take over discount calculation.

Votes for this answer: 1
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you very much for the detailed guidance.

We'll try that.

Adrian

 
Jonas Krarup Dam
Reply

Note to others who may try to use IDiscountExtenderCalculateProductDiscount and implemen GetDiscount():
The priceInfo you return in GetDiscount will only be used correctly if you:
*  set "discount type" to "Amount from field",
or
* set it to "Percentage" and enter 100%.
 

 

You must be logged in to post in the forum