开发者

Looking for patterns/best practices for calculating complex discounts [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
开发者_如何学运维

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago.

Improve this question

I'm developing a price calculation engine. I've looked all over and there's nothing that really fits what we need. However, I'm now looking how to implement specific prices and/or discounts. I don't want to introduce a rule based engine to my end-users, because they won't get it.

For example, when you order an ItemX the price is $30. But in combination with ItemY the price of ItemX is $20. Or when ordering five of ItemX, each after it will be only $15.

Any ideas on where to start? How to take this on? Perhaps some (open source) example applications that contain practices like these? Any (technical) patterns I could use? Preferably in C#. Thanks in advance!


There are many ways you can achieve this, but I think the one which might be most useful for you would be to define a DSL that you can use to express your discounts in such a way where they can be easily explained and rationalised with business users. An example from one of ayende's articles on DSLs in boo is:

apply_discount_of 5.percent:
     when order.Total > 1000 and customer.IsPreferred
     when order.Total > 10000

suggest_registered_to_preferred:
     when order.Total  > 100 and not customer.IsPreferred

As you can see you can see, this is the kind of thing you can print out and show to a client and they will immediately understand what's going on.

Of course developing something like this is time consuming, expensive and fraught with funky edge cases. However it has the benefit of being code which can be unit tested, executed and debugged.

If boo isn't your thing, then maybe you could look at defining something similar in ironruby, ironpython or F#. I would however suggest staying away from XML for defining these rules unless you really enjoy a world of pain.

This is however the kind of thing that products like Biztalk were designed to handle. Which rules engines have you evaluated and found lacking?


We use a Rule Engine for this type of complex calculation. Our platform is Java and we use Drools (which we're happy with). Drools is also available for .Net. Here's a list of open source Rules Engines for .NET.


I am sorry to have to say this, but this would seem like you would have to apply some Pricing Rule Engine to achive what you are after.

Would seem like you have to

  • Store the available items, and their discounts on per pruchase.
  • Store which items in combination would discount each other.
  • Also maybe thinking of per unit/quantity purchased per unit, or maybe per package/special.
  • Might want to look at keeping a archive/storage of these specials/packages, just incase the customer wants a reprint of the original invoice.

In general there is a lot of possible rules/combinations that can be thought of, and you as developer can implement these and hide them from the user, or allow the user to create them, but somebody has to do so.

And then, when you dont feel like implementing your own, GOOGLE shold provide some:

Open Source Rule Engines

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜