Brown Limie
Brown Limie

Reputation: 2599

Groupon coupon code system in PHP

I am trying to create a system just like groupon but where merchants input voucher codes into the system that customers can use to get their products.

So let's say Merchant 1 has the following product

He would add coupon codes for Product ID 2 into the system.

Coupons get added to the COUPON table with the following fields:

max is the maximum of the coupon that can be given out. num_available is the number of that coupon available. So if a Merchant puts in 5 as max, then num_available starts out as 5. but whenever a customer gets assigned that coupon, num_available gets decreased by 1

Then when customers order they get assigned a coupon

User orders get added to the following table Orders: Orders:

OrderPosition:

Each Order (stored in Orders) has multiple products associated with it (stored in OrderPosition).

So User 1 orders Product 2 and gets assigned Coupon ID 1 that was added for Product 2. The num_available for Coupon ID 1 (in the COUPON table) gets decreased by 1 in the database.

but what if User 1 orders TWO Product 2s - one for her and one for her friend - does she get two different coupon codes?

Basically, I would like to make his process more efficient, and I don't know how Groupon has designed this process, but if anyone has good ideas on how best to do so, please let me know!

I would love to know if I should change the database schema to make this more efficient ...

My end goal is to allow people to buy deals. Once they buy a deal, they get a coupon. I could have automatically generated that coupon, but I'm guessing some merchants want to input their own coupons that work on their own system, right?

The question is - how should I design the system to achieve my goals described above?

I would also like to stress that the products that will be listed on my website will be from different merchants. I won't be listing my own products. Merchants list their own products just like on Groupon.com.

Is it feasible to generate coupon codes instead of having merchants input their codes? Wouldn't that mean that they would have to also support these codes on their own systems? Like If jcpenny.com inputs products on my website, I could generate coupon codes for these products, but what if jcpenny.com does not support these coupon codes? I am guessing that Merchants would want to input their own codes... Or maybe I am wrong?

Upvotes: -5

Views: 1990

Answers (1)

galchen
galchen

Reputation: 5290

i'd suggest generating a coupon code for each request. if someone orders 2, generate 2 codes.

it's easier if someone buys for a friend, or if the same user buys multiple times. i actually had the same case in a system i wrote, and it ended up being the most convenient solution for my case.

of course, it's a matter of opinion...

Upvotes: 2

Related Questions