Anytime you modify a object, candidate rules are going to be re-examined.&nbsp; 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>&nbsp; $c: Cart(contents contains &quot;TV&quot;, contents excludes &quot;free VCR&quot;)<br>then<br>&nbsp;$c.add(&quot;free VCR&quot;);<br>&nbsp;modify($c);<br>end<br><br>rule RemoveVcr<br>when<br>&nbsp;$c: Cart(contents excludes &quot;TV&quot;)
<br>then<br>&nbsp;$c.remove(&quot;free VCR&quot;);<br>&nbsp;modify($c);<br>end<br><br>You can fill in the rest.&nbsp; Like I said, you probably need some state variables so things don&#39;t loop, need to exclude the case where a non-free VCR is legitimately in the cart, etc.&nbsp; But your basic question should be answered with this approach.&nbsp; Don&#39;t think procedurally, think in terms of a living system when the changes in objects trigger somewhat asynchronous cascades of matching rules.&nbsp; 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> &lt;<a href="mailto:MJohnston@pubgroup.com">MJohnston@pubgroup.com</a>&gt; 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>