[rules-users] rules for promotional offers
Wolfgang Laun
wolfgang.laun at gmail.com
Fri Sep 9 01:34:15 EDT 2011
Your rule exhibits procedural thinking. (For an aspiring rule programmer his
is typical teething troubles.)
There's no need to collect all A's and B's in order to determine their
number being greater than one or two - this is achieved automatically by a
simple triple match rule. Consider
rule "2A - 1B"
when
$a1: CartItem( productId == "A", processed == false )
$a2: CartItem( this != $a1, productId == "A", processed == false )
$b: CartItem( productId == "B", processed == false )
then
modify( $a1 ){...}
modify( $a2 ){...}
modify( $b ){...}
end
Note:
- The modify is essential. (When you say "doesn't work", always provide
details.)
- Use the field name rather than the getter call - it improves
readability.
- I'm not sure whether 5.2.0 final handles boolean fields correctly -
IIRC, there were some issues. It's possible that CartItem(..., !processed)
works.
-W
2011/9/8 Sandeep Bandela <gibsosmat at gmail.com>
> Hi,
> I am new to rules engine, after going through the examples shipped
> (shopping.drl, petstore.drl)
> I am trying to implement promotional discounting using drools 5.2.0 final,
> stateful session. assume cart has all the items that customer wants to buy,
> I am trying to bundle them together with the existing offers
>
> rule "Buy X units of Product A and Get Y units of Product B Free"
> dialect "java"
> when
> $itemsA : ArrayList( size >= 2) from collect( CartItem( getProductId()
> == "A", !isProcessed()))
> $itemsB : ArrayList( size >= 1) from collect( CartItem( getProductId()
> == "B", !isProcessed()))
> then
> // current scenario buy 2*A and get 1*B
> int x = 2;
> int y = 1;
> for(int i=0 ; i < x ; i++){
> CartItem $ci = (CartItem) $itemsA.get(i);
> // modify($ci){setProcessed(true) ... } dosent work
> $ci.setProcessed(true);
> $ci.setItemDiscount(0.0);
> $ci.setBundleId(bundler.getId());
> }
>
> for(int i=0 ; i < y ; i++){
> CartItem $ci = (CartItem) $itemsB.get(i);
> $ci.setProcessed(true);
> $ci.setItemDiscount($ci.getPrice());
> $ci.setBundleId(bundler.getId());
> }
> // global counter to identify bundled items
> bundler.increment();
> end
>
> the above rule calculates only for 1 set of offer i.e first 2*A & 1*B are
> considered, rest in the cart are not bundled.
> if customer buys 4*A + 2*B it dosent consider it. am I missing anything? is
> this the right way to do it?
> any feedback is appreciated.
>
>
>
>
> --
> Regards,
> Sandeep Bandela.
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110909/617e2a2c/attachment.html
More information about the rules-users
mailing list