I'm developing an ecommerce website and I need to be able to define certain package deals consisting of different products. These special offers can be as simple as buy 5 of one product and you get a special price or as complicated as buy 15 of of any of 20 different products (any combination as long as there are 15 items and they are all from the range of 20 products)
So I need to store these special offer/discount rules somehow. I was thinking I have a parent table of special offers/discounts and a child table storing the actual rules.
I'm planning that the rules table stores a fieldname, operator and value so I can store multiple rules per offer to build up the whole discount rule e.g. to apply a discount if someone buys more than 10 of MP0001 as well as more than 10 of MP002 the rules for that discount would be:
Discount A Rule1
ProductID = MP0001
Quantity > 10
Discount A Rule 2
ProductID = MP0002
Quantity > 10
and to qualify for discount A both rule 1 and 2 must be true.
I have found I can use eval() to run dynamic if statements such as:
eval("if ($MyField $MyOperator $MyValue) {echo \"True\";} else {echo \"False\";}");
Does anyone have any thoughts on storing discount rules this way? (or if there's a better way or handling complex special offer/discounts?)
Thanks.