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:<br><br>rule AddVcr
<br>when<br> $c: Cart(contents contains "TV", contents excludes "free VCR")<br>then<br> $c.add("free VCR");<br> modify($c);<br>end<br><br>rule RemoveVcr<br>when<br> $c: Cart(contents excludes "TV")
<br>then<br> $c.remove("free VCR");<br> modify($c);<br>end<br><br>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.
<br><br><div><span class="gmail_quote">On 2/13/07, <b class="gmail_sendername">Matt Johnston</b> <<a href="mailto:MJohnston@pubgroup.com">MJohnston@pubgroup.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I am working on rules for an online shopping cart. Depending on the<br>products in the cart, the customer may get certain discounts.<br><br>If cart contains a TV, add a free VCR.<br><br>I can apply these rules, but what about rolling them back?
<br><br>So in the example above, the rule automatically added a free VCR because<br>the cart contained a TV. If the customer removes the TV, I need to roll<br>back the VCR rule and also remove the VCR from the cart.<br><br>
Does anyone know how to do this? Is it possible?<br><br>Matt Johnston<br>Manager of Internet Content<br>Publishing Group of America<br>p: 615-468-6053<br>f: 615-468-6153<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">https://lists.jboss.org/mailman/listinfo/rules-users
</a><br></blockquote></div><br>