Jump to content


This topic is now archived and is closed to further replies.


Coupon Code System

Recommended Posts

I have a fully functioning shopping cart script now thanks to the help of this forum, but I'm wanting to add a coupon code box. Could someone tell me how to implement this. My cart products are stored in a session and only the ids, name, and price are stored in the database. Could someone please walk me through and give me a good starting point on:

Adding a coupon code field
Where to store the coupon codes
Suggested methods

Any information would be greatly appreciated thanks.


Share this post

Link to post
Share on other sites
Well it's impossible to say what would work best for you without knowing how the rest of the code is implemented, but here is what I would do.

add on to your product object or derive a new one  as a child of the product object. The constructor (or a some method) would take the cupon code as a parameter and use it in a switch case to pick a memory reference to the apropriate function that "discounts" the itmes (unless you will only be discounting in one way instead of beig specific the the coupon).  Each of you products would check to see if a cupon code is defined, and if so, parse it through to see if it can discount itself, and if so, what discount it should apply. You might want to also keep a database of coupon codes which lists each product ID it would apply to. The object would check to see if it finds itself in this list before discounting it's price.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.