See a few comments at the end. rule "assign discount" when $c: Cart( discount == null, $on: online, $citems: items, $age: age, $shipping: shipping ) $p: Param( online == $on, $pdisc: discount, $pitems: items, minage <= $age, shipping == Param.NA_SHIPPING || == $shipping, eval($citems.containsAll($pitems)) ) not Param( online == $on, discount > $pdisc, $xitems: items, minage <= $age, shipping == Param.NA_SHIPPING || == $shipping, eval($citems.containsAll($xitems)) ) then modify( $c ){ setDiscount( $pdisc ) } end
* To revert the Cart to discount == null etc., use another rule, triggered by a "command" fact, which is retracted by the very same rule. * items is a Set<String> which can be easily maintained in addition to a List<Items>. Or add methods supporting the required set operations, computing the Set<String> on the fly. * Note the use of a dedicated value for "don't care", e.g. NA_SHIPPING. * An entirely new criteria will have to be accomodated in the (single) rule, but the example covers discrete values and sets; take care when there could be ranges, as with age. -W On 19/02/2013, pdario <dario.piantan...@gmail.com> wrote: > laune wrote >> I'm confident that there's a clean and manageable way of preparing >> this data to work in combination with a small and constant set of >> rules. I refrain from elaborating this in all details without knowing >> all of the requirements. > > I'll try to summarize them as properly as I can... > > Rule 0: default condition > If cart is paid "offline", it has 0% discount > > Rule 1: online payment discount > If cart is paid "online", it has 10% discount > > These two are fixed and always valid. > > Then we monthly decide a list of items that grant different discounts on > the > whole cart over the 10% of Rule 1 (i.e. Rule 1 must be true to get further > discount). > > For example: > Rule 2: valid for February 2013, item A > If cart is paid "online" and contains item A, it has 15% discount > Rule 3: valid for February 2013, item B > If cart is paid "online" and contains item B, it has 17% discount > > Next month, both items and discount levels will change > > We need the firt Rule 0 because the user can change the payment method, so > we have to reset the discount to 0. > > Ideally, we would like to left the Rule 0 and 1 unchanged (as they are > basic > rule) and manage the monthly rules without impact on them. > > To make things worse, our business people not only rely on items contained > in the cart, but each month they decide a different attribute from the cart > or user to be taken into account for special discount, so that the examples > above may read like: > > Rule 2: valid for February 2013, item A > If cart is paid "online" and contains item A and the user is older than 30, > it has 15% discount > Rule 3: valid for February 2013, item B > If cart is paid "online" and contains item B and the cart is shipped within > Europe, it has 17% discount > > As you remember, we used salience and activation groups, but this prevents > us from applying rules to a bunch of carts, as the rule activation cancels > other activations. > > Do you see a cleaner design? > > Thank you a lot for support. > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Evaluate-rules-for-multiple-facts-of-the-same-type-within-a-StateuflSession-tp4022157p4022441.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > _______________________________________________ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users