Anytime you modify a object, candidate rules are going to be re-examined.
You may need some state variables in addition to this (to control when rules
fire, avoid loops, etc), but the basic rules could be:
rule AddVcr
when
$c: Cart(contents contains "TV", contents excludes "free VCR")
then
$c.add("free VCR");
modify($c);
end
rule RemoveVcr
when
$c: Cart(contents excludes "TV")
then
$c.remove("free VCR");
modify($c);
end
You can fill in the rest. Like I said, you probably need some state
variables so things don't loop, need to exclude the case where a non-free
VCR is legitimately in the cart, etc. But your basic question should be
answered with this approach. Don't think procedurally, think in terms of a
living system when the changes in objects trigger somewhat asynchronous
cascades of matching rules. Calling modify() on a fact is like restarting
the whole matching algorithm for any rules that had that fact included in
their (possible candidate) constraints.
On 2/13/07, Matt Johnston <MJohnston(a)pubgroup.com> wrote:
I am working on rules for an online shopping cart. Depending on the
products in the cart, the customer may get certain discounts.
If cart contains a TV, add a free VCR.
I can apply these rules, but what about rolling them back?
So in the example above, the rule automatically added a free VCR because
the cart contained a TV. If the customer removes the TV, I need to roll
back the VCR rule and also remove the VCR from the cart.
Does anyone know how to do this? Is it possible?
Matt Johnston
Manager of Internet Content
Publishing Group of America
p: 615-468-6053
f: 615-468-6153
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users