A user can buy less than 1 quantity since it's a decimal, you can implement having added something with 0.5 qty in the cart. Sure, most often it's an integer value of the quantity in our implementatios, but the promotion engine can't know this.
That's a good point.
But is there a way to override this behavior? When using a price service, and I am looking for prices I can set quantity I want. It'd be nice if same could be applied for promotion engine.
My question is why would you want both 0 and 1 MinQuantity prices? Without the promotion, what is the price the customer will get when they add the item to the cart?
The default price is always the price with Quantity = 0. If you want to change the behavior, implement your own ReadOnlyPricingLoader and override GetDefaultPrice to ask IPriceService to return price (with quantity) you want to.
The price with 0 is a price we display a user as an "initial" price while the price with 1 is an actual sale price.
Now when a customer adds an item to the cart, it gets discount correctly.
Not saying that's wrong, but it's different with how Episerver "sees" the price. As a framework it has to care about decimal quantity - as Joel said - and 0 is the default minimum quantity. Yours is a different way of using minimum quantity and this can conflict with other parts of the framework.
So you can do like I mentioned, or you can use special sale code (like "MSRP") for storing "initial" price. Both will have minimal quantity = 0, and the promotion system will only care about the default price without sale code.
The use case is pretty common and as far as I know there is no native support for it in Commerce. We've solved it by hacking around with different price entries with different combination of sale type/sale code (or customertype), since we don't use that feature.
Thanks, Quan! Probably it is the way to go (just have to rework a lot :) ). It did work before we started to use promotions which can be applied to the products not added to the cart yet.
But that's for a B2C site, I think you'd want to use it differently for a B2B site.
I think this should be what you are looking for.
https://world.episerver.com/blogs/Shannon-Gray/Dates/2016/11/promotion-engine-sale-price-customization/
I do believe you are making it much harder for yourself.
The promotion engine uses IPriceService.GetDefaultPrice for it's calculations.
All you have to do it implement your own IPriceService and register it and you are all set.
Making it a decorator of the standard implementation and just override the GetDefaultPrice function will mean a minmum of code.
I have two prices for the product:
One price has minimum quantity 0 and the second - 1.
When I call a promotion engine's method GetDiscountPrices, it calculates the discount from the first price.
It is wrong because there will be no way for the user to buy 0 amount of the product. Minimum quantity all promotions should calculate the price from should be 1. It really confuses customers that they see one price on the product page, but when they put the product in the cart, they get discounted price.
Is there a built-in way to override this behavior?