Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

itsgoku's avatar

Complex coupon/offers system

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 :

  1. Discount on particular item.
  2. Discount on a whole category.
  3. Specific User based coupons.
  4. % based coupons.
  5. 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?

0 likes
3 replies
igorblumberg's avatar

@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)

http://www.daveegerton.com/assets/images/database-schema-prestashop.png

good luck!

itsgoku's avatar

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?

Please or to participate in this conversation.