I am trying to build a coupon functionality to an ecommerce website where in the user can apply various kinds of coupons/offers.
Some of the most important types of offers/coupons would be :
Discount on particular item.
Discount on a whole category.
Specific User based coupons.
% based coupons.
referral based coupons (optional)
What I could think of was using a coupons database table which could hold important information about the coupons. like their type, and their specific values depending upon it.
Say, I have % based coupon, then it would have how much % field and other fields will be empty.
It seems to me that this system might break easily! Any reference or how would you guys do it? Also, how should I implement it in the logic?
@itsgoku
When I find myself in situations like yours I look for open source projects and it's solutions.
I've worked with prestashop on the past and I'm familiar with it's DB and data structure.
They have only a "value" field and an "id_type". Based on the type you know if it's percentual or absolute. I think it's better then having a "percent_value" and "absolute_value" on the DB.
On the link bellow you can see prestashop's DB schema. The discounts table are in the middle (light purple)
Thanks @igorblumberg . That was really helpful. Seemed like a lot what I had in mind.
Any thing about the referral coupon system? That still seems sketchy to implement with schema tbh. Like for giving a cashback to wallets?