Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Remove decimals on discounted prices?

Vote:
 

[Commerce 12.17.2]

Hi 

I'm working on implementing the Promotions module on an old Commerce 12.17 site. This is going fine, except for one thing...

It was decided a long time ago that the site should not show any decimals on prices (except for tax values), and the decision was made to just cut off all decimals (i.e. round down).

This worked fine, because all prices was integers. BUT the problem now arises when something costs 299 SEK, and there is a 50% discount, the discounted price is 149,50 SEK, which gets rounded up to 150 SEK. I want it to be rounded down instead, to 149 SEK.

I tried creating my own implementations inheriting from DefaultLineItemCalculator and DefaultPlacedPriceProcessor, but the prices are already rounded up when they get to the various methods in them (which I've checked using breakpoints), except for one of the many, many calls to DefaultLineItemCalculator.CalculateDiscountedPrice() where it actually was 149,50, and I could truncate that down to 149 SEK.

Is there a better place to do this? Some interface I'm missing somewhere? Maybe create my own version of the PromotionEngine?

#291001
Nov 02, 2022 17:24
Vote:
 

Hi Patrik,

Create your own Promotion. Then can dictate what gets returned when CalculateDiscountedPrice is called.

https://docs.developers.optimizely.com/commerce/v13.0.0-commerce-cloud/docs/custom-promotions

#291182
Edited, Nov 06, 2022 17:01
Vote:
 

Hey,

I don't have a solution to this problem but we're facing the same difficulties. The client wants whole number discounted prices. Didn't think it was going to be that hard implementing but I couldn't either find any information regarding this. We've implemented custom LineItemCalculators and custom OrderGroupCalculator to be able to use the built in money rounding in .NET, but we're having to much custom logic in my opinon. Also seem to face some edge-case scenarios where tax calculation of rounded prices are giving incorrect taxes. 

Going to look into creating custom promotions like Surjit suggested. Either way I would vote for having some more information regarding rounding in the documentation :)

#292843
Dec 08, 2022 8:51
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.