Hi Wolfgang,<br>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.<br>
<br>rule "Apply 10% discount if you purchase 2 items"<br> dialect "java"<br> when<br> $s1 : CartItem( getProductId() == 236061, !isProcessed())<br> $s2 : CartItem( getProductId() == 236061, getId() != $s1.getId(), !isProcessed())<br>
$m : RuleMessage()<br> then<br> $m.addMessage("Found item1: " + $s1.getName() + " id: "+$s1.getId());<br> $m.addMessage("Found item2: " + $s2.getName() + " id: "+$s2.getId());<br>
modify($s1){<br> setProcessed(true),<br> setPromoItemDiscount($s1.getPrice() * 0.1),<br> setPromoId("1"),<br> setBundleId(bundler.getId()),<br> setAggrigatorId(1)<br> };<br>
modify($s2){<br> setProcessed(true),<br> setPromoItemDiscount($s2.getPrice() * 0.1),<br> setPromoId("1"),<br> setBundleId(bundler.getId()),<br> setAggrigatorId(1)<br> };<br>
bundler.increment();<br>end<br><br><div class="gmail_quote">2011/9/9 Wolfgang Laun <span dir="ltr"><<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Your rule exhibits procedural thinking. (For an aspiring rule programmer his is typical teething troubles.) <br><br>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<br>
<br>rule "2A - 1B"<br>when<br> $a1: CartItem( productId == "A", processed == false )<br> $a2: CartItem( this != $a1, productId == "A", processed == false )<br> $b: CartItem( productId == "B", processed == false )<br>
then<br> modify( $a1 ){...}<br> modify( $a2 ){...}<br> modify( $b ){...}<br>end<br><br>Note:<br><ul><li>The modify is essential. (When you say "doesn't work", always provide details.)</li><li>Use the field name rather than the getter call - it improves readability.</li>
<li>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. <br></li></ul>-W<br><br><div class="gmail_quote"><div><div>
</div><div class="h5">2011/9/8 Sandeep Bandela <span dir="ltr"><<a href="mailto:gibsosmat@gmail.com" target="_blank">gibsosmat@gmail.com</a>></span><br>
</div></div><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex"><div><div></div><div class="h5">Hi,<br>I am new to rules engine, after going through the examples shipped (shopping.drl, petstore.drl)<br>
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,<br>
I am trying to bundle them together with the existing offers<br><br>rule "Buy X units of Product A and Get Y units of Product B Free"<br> dialect "java"<br>
when<br> $itemsA : ArrayList( size >= 2) from collect( CartItem( getProductId() == "A", !isProcessed()))<br> $itemsB : ArrayList( size >= 1) from collect( CartItem( getProductId() == "B", !isProcessed()))<br>
then<br> // current scenario buy 2*A and get 1*B <br> int x = 2;<br> int y = 1;<br> for(int i=0 ; i < x ; i++){<br> CartItem $ci = (CartItem) $itemsA.get(i);<br> // modify($ci){setProcessed(true) ... } dosent work<br>
$ci.setProcessed(true);<br> $ci.setItemDiscount(0.0);<br> $ci.setBundleId(bundler.getId());<br> }<br> <br> for(int i=0 ; i < y ; i++){<br> CartItem $ci = (CartItem) $itemsB.get(i);<br>
$ci.setProcessed(true);<br> $ci.setItemDiscount($ci.getPrice());<br> $ci.setBundleId(bundler.getId());<br> }<br> // global counter to identify bundled items<br> bundler.increment();<br>end<br>
<br>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.<br>if customer buys 4*A + 2*B it dosent consider it. am I missing anything? is this the right way to do it?<br>
any feedback is appreciated.<br><br><br><br clear="all"><br>-- <br>Regards,<br><font color="#888888">Sandeep Bandela.<br><br>
</font><br></div></div>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Sandeep Bandela.<br><br>