Developer forum

Forum » Development » Discount calculation removed if in cart question

Discount calculation removed if in cart question

Jan Sangill
Reply

Hi,

This subscriber: Ecommerce.Discounts.AfterDiscountCalculation

I see this is the API - but from what version? I have a 9.7.5 and cant find it. I can only find BeforeDiscountCalculation.

What I am trying to accomplish is that I need to remove all discounts if a product has  a certain metafield checked. So if a orderline consist of a mix between two types, only the discounts should be applied to the correct ones.

Is this subscriber "AfterDiscountCalculation" the correct one to use for this - or do we have a smarter method to accomplish this?

Info: I cant use the "Exclude products or groups feature in DW admin - since this would be to slow".

/jan


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Jan,

The AfterDiscountCalculation notification is available in DW 9.8. You might be able to use Order.BeforeSave notification instead (check if order.IsCart and then change the order).

However, It's a little weird that you need to remove discounts like that. Can't you configure your discounts so that they only apply to the right products by putting those products in a special group or something?

Best regards,
Morten

 
Jan Sangill
Reply

Hi,

Order.beforeSave when is that run? Because the cart itself should not display discounts either. So the discounts should be removed whenever a cart is shown and from there on out.

In regards to configuring it differently. That might not be a solution - since its not its not only group dependant/product dependant - but might also be dependant on user settings on people logged in. But if not, will most likely be going that way.

 

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Jans,

 

I suggest you check Discount Extenders https://doc.dynamicweb.com/api/html/73209394-6acc-5a2e-58bb-0817ed607d6d.htm

 

I've dealt with a lot of discount related issues over the years and essentially calculating discounts always comes with a performance cost, specially because DW always needs to re-check/re-calculate them whenever something happens to the cart, since conditions might change.

 

That said, going through all that process to then remove them, seems like a waste of computing cycles, which you can optimize by developing your own logic through the extenders.

 

Best Regards,

Nuno Aguiar

 
Jan Sangill
Reply

Hi Nuno or Morten,

When I take the discountextender from the examples on the site - then it cant find the "DiscountExtenderBase".

I am able to find it on 9.7, but on this site 9.6.6 its not there.

You know from what version this is supported? or is the code simply different in 9.6.6?

 


 

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

Hi Jan,

The DiscountExtenderBase was added in the 9.7.0 release. However, some changes have been made since to make it more useful, so I would suggest that you upgrade to 9.7.6 or later.

Best regards,
Morten

Votes for this answer: 1
 
Jan Sangill
Reply

Hi, TY for the response. The discountExtender did exactly what I needed!

 

You must be logged in to post in the forum