[rules-users] rules for promotional offers
Sandeep Bandela
gibsosmat at gmail.com
Fri Sep 9 03:10:36 EDT 2011
Hi Wolfgang,
This is what I did initially but for product > 2 I didnt find a generic way
to do this. following is my first rule. I didnt use field names because it
was giving error that member is not accessible. I will attach the errors of
each case in a few mins.
rule "Apply 10% discount if you purchase 2 items"
dialect "java"
when
$s1 : CartItem( getProductId() == 236061, !isProcessed())
$s2 : CartItem( getProductId() == 236061, getId() != $s1.getId(),
!isProcessed())
$m : RuleMessage()
then
$m.addMessage("Found item1: " + $s1.getName() + " id:
"+$s1.getId());
$m.addMessage("Found item2: " + $s2.getName() + " id:
"+$s2.getId());
modify($s1){
setProcessed(true),
setPromoItemDiscount($s1.getPrice() * 0.1),
setPromoId("1"),
setBundleId(bundler.getId()),
setAggrigatorId(1)
};
modify($s2){
setProcessed(true),
setPromoItemDiscount($s2.getPrice() * 0.1),
setPromoId("1"),
setBundleId(bundler.getId()),
setAggrigatorId(1)
};
bundler.increment();
end
2011/9/9 Wolfgang Laun <wolfgang.laun at gmail.com>
> 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
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
--
Regards,
Sandeep Bandela.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110909/7a920380/attachment.html
More information about the rules-users
mailing list