Personally, I'd make the configuration language Perl code that can be evaluated. I'd have this generated programmatically from an interface the user can understand. I'd store the code in the database along with the product. I'd also store enough of the rules that went into creating the Perl code in the database that the UI could show the original rules for perusal. Finally, I'd have a field specifically to tell in what order the rules ar eto be applied.

I have a specific idea of how I'd do the rules entry interface if you're interested...

The interface I picture allows 3, 5, 10, or however many rules you want per item. I'd have a way at the top or bottom of the form (or widget, however you want the interface implemented) to specify which rules you ant applied and in which order.

Then I'd have a section for each rule. This comes in two smaller sections per rule, a condition and an adjustment.

For the mathc seciton, I'd first have the word 'If'. Then I'd have a select tag or drop-down box of some sort for conditions, such as 'past user purchases', 'product count', 'user class', and whatever. Then I'd have a way to select 'is the same as', 'is not the same as', 'is greater than', and 'is less than'. Then, I'd have a text entry box to put in the values you're matching against.

Now we go on to the adjustment section. I'd have a drop-down box for which variable of the purchase you'd like to change (usually the price, but shipping cost/weight/distance are good ones, too). Second in this section I'd have a selection of some sort (drop-down or radio buttons) among 'change to', 'reduce by', or 'increase by' (and possibly others later on). Then, I'd have a text box or numeric drop-down box(es). Finally, I'd have a selection of some sort between units of money and percentages (or possibly even units of weight, distance, etc. depending on how you'd like to discount shipping or whatever else).


From the rules listed in the my UI description, it's easy to generate code in the style of simple if statements. The specific ordering lets you do each one independent of the others, in the order specified by the user. The only thing this doesn't take into account in the simple manner of its design is to make the rules interact based on the results from the other rules. Even that should be possible with extra variables to be set and checked, but that's beyond the scope of this node and is left as an exercise for now.

Christopher E. Stith
Do not try to debug the program, for that is impossible. Instead, try only to realize the truth. There is no bug. Then you will find that it is not the program that bends, but only the list of features.

In reply to Re: Seeking configuration language for rules based system. by mr_mischief
in thread Seeking configuration language for rules based system. by ehdonhon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.