I’m currently designing a database for my company’s website. I would like to create a table which will hold information (logic) about our discounts so that I can just call a function with a discountID and my php code will calculate the new price. My question is, every discount has different logic. ex. 10% off, $10 off, by one get one free, buy 3 get 50% off…
How can I store this in the database so that my code can calculate the discount on its own?
A database does not store logic – only data. Split this into three fields:
So for one discount you might store the following:
For another, where BOGOF applies:
Then it would be up to your PHP to receive these values and act accordingly.