It sounds to me like you should build it so you can just get a count of
matching item names, instead of having separate conditions checking each
name.  Your condition would check the count being > 1 instead.

> -----Original Message-----
> From: Bouis, Laurent [mailto:[EMAIL PROTECTED] 
> 
> I am new to drools, trying to see if I could use it to 
> implement a discount engine.
> 
> I am playing with the petstore example (shopping cart), and I 
> was wondering if Drools has a pattern matching feature or 
> not, if rules can be fired based on combinations rather than 
> permutations.
> 
> For example I want to implement a buy 2 Gold Fishes get 1 
> free discount.
> 
> If I define my rule like:
> 
>   <java:condition>item1.getName().equals( "Gold Fish" 
> )</java:condition>
> 
>   <java:condition>item2.getName().equals( "Gold Fish" 
> )</java:condition>
> 
>  
> 
>   <java:consequence>
> 
>       //gives 100% discount to one item
> 
>       item2.setDiscount(100);
> 
>     </java:consequence>
> 
>  
> 
> If the user puts 2 Golf Fishes in his cart (A, B), the rule 
> will fire 4 times (for permutation (A,A), (A,B), (B,B), (B, 
> A), and gives 100% discount to all items...That does not work.
> 
>  
> 
> I can add a condition to make sure the items are different 
> and the rules fires only once per combo such as 
> 
> <java:condition>item1.getId()>item2.getId()</java:condition>
> 
>  
> 
> That works in this case, but it is not scalable at all (if I 
> want to do 4 gold fishes get 1 free...it gets more complicated).
> 
>  
> 
> I also want the rule to fire more than 1 time if the user has 
> let's say 8 gold fishes (he should get 4 free), so having a 
> condition on the cart itself such as cart.hasXitems(4, 
> "GolfFish") would probably not work I suppose (such rule 
> would be fired only once if I understand how the engine works).
> 
>  
> 
>  
> 
> So how would this (buy X items, get 1 free; applicable more 
> than 1 time per cart) be implemented in a scalable and 
> elegant way with drools? 
> 
> Is there some kind of pattern engine in drools (not sure if 
> this is the proper term for this, but basically I want the 
> rule to be fired only once per combination of facts that 
> match some conditions, not per permutation..)?
> 
>  
> 
>  
> 
> Thanks.
> 
>  
> 
>  
> 
>  
> 
> Laurent
> 
>  
> 
>  
> 
> 

Reply via email to