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.