close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Unique codes for discounts vouchers

Thread began 6/30/2011 11:10 pm by Fritz Stickers | Last modified 8/08/2012 1:30 pm by elevy388997 | 3524 views | 8 replies |

Fritz Stickers

Unique codes for discounts vouchers

I'am looking for an example from a database driven coupon (code) system.
Is there a way to create unique codes automatically and that they just can be used once ?

Sign in to reply to this post

Jason ByrnesWebAssist

  I'am looking for an example from a database driven coupon (code) system.  


Here are the basic steps for setting up database driven promocodes:

First off, you should follow the solution recipe for static coupon codes to get coupon codes working. That tutorial can be found In the Solution Recipes section of the eCart Support Page titled "Creating a Coupon system for your eCart store":
ecart/


To convert that to be database driven:

1) Create a table in your database to hold the coupon codes. it should have a structure similar to:
couuponID - Auto Number, Primary key Column.
couponCode - varchar
couponAmount - double


To add a coupon code of "test" that will give a 10% discount, you would create the follwoing record:
couponID | couponCode | couponAmount
1 | test | 0.10

2) Next is to add a recordset to the page to lookup the coupon amount based on the code the user enters.

On the server behaviors panel, click the plus button and select Recordset. In Simple view, set the record set to use the coupon table we created. Set the name of the recordset to "rsCoupon" In the Filtering Section, set it to filter the couponCode column Equal to the Form Variable txtPromoCode, this is name of the text box created in the coupon code system tutorial.

3) Now we need to create another session variable to hold the discount amount. On the server behaviors panel, click the plus button and select eCart -> General -> Set Session Value. Set the trigger to "recordset rsCoupon Not Empty". Set the name of the session variable to "PromoAmount". Click the lightning bolt next to value, expand the rsCoupon recordset and select the couponAmount column.

4) The PromoCode session variable needs to be modified as well. Set the trigger to "recordset rsCoupon Not Empty" so it will only get set if the promcode sexists in the database.

5) The last step is to modify the Promotional Discount rule in eCart. Remove the "If Session variable == WebAssist" triger.

Add a new trigger "Session variable exists "PromoCode""

Add another trigger "Session variable exists "PromoAmount""

Then Modify the charge rule "Bases on Cart SubTotal "Times" "$_SESSION['PromoAmount']"

so that the discount will use the value stored in the session variable from the database.


  Is there a way to create unique codes automatically and that they just can be used once ?  




for this you could use the security assist random password generator to generate the unique code.

on checkout delete the coupon code from the database so it cannot be used again

Sign in to reply to this post

elevy388997Beta Tester

How would I make it so the coupon created ends at a certain date, and not a one time use only deal?

Example. Admin logs in, clicks on coupon section and has these options:

Coupon Code:
Discount Amount:
End Date:

Then once it is in there, a row appears below these options showing Code, Amount, End Date, Times Redeemed... along with an edit and delete option.

Sign in to reply to this post

Jason ByrnesWebAssist

the coupon table would need a column for end date.

the recordset that is used to lookup the coupon amount would need to be edited to also return the end date column

When setting the amount and code session variables, another set session variable would be needed to store the end date value.

In the coupon rule, you could add another trigger for Today is before a certain day and use the session for comparison.

to track how many times the coupon is redeemed, the order table would need a column to store the coupon code.

you would need to update the store order summary behavior to bind the coupon code column to the coupon code session variable.

in the admin section you would need to create d a recordset using the COUNT() function to count the number of times the coupon was used, for example:

SELECT COUNT(OrderID) as timesRedeemed FROM orders WHERE couponCode = "your Coupon"

Sign in to reply to this post

elevy388997Beta Tester

Would there also have to be a Column for RedeemCount in the coupon table? Or does it go in the orders table because that is when they would type in the coupon to apply it?

Sign in to reply to this post

Jason ByrnesWebAssist

no, to return a count of how many times the coupon is used, you would use a recordset using the COUNT function for example:
SELECT COUNT(OrderID) as timesRedeemed FROM orders WHERE couponCode = "your Coupon"

Sign in to reply to this post

elevy388997Beta Tester

I saw that line and figured "timesRedeemed" was a column in a table. How does the COUNT function work if it isn't increasing a number somewhere each time the coupon is used with an order?

Sign in to reply to this post

Jason ByrnesWebAssist

the idea is that when an order is p,aced, a new record is stored in the order table. in the order table you store the coupon code that was used.

the count() function returns a count of the number of rows in the database.

lets say the coupon code is "12345" and there are 8 records in the database where that coupon code was used. the recordset:
SELECT COUNT(OrderID) as timesRedeemed FROM orders WHERE couponCode = "12345"

would return the value 8, "timesRedeemed" is an alias given to the result.

Sign in to reply to this post

elevy388997Beta Tester

Ohhh, so instead of creating extra tables and columns yadda yadda you just search the order records for a coupon used. Thanks Jason!

Sign in to reply to this post

graham

Jason, I have static coupon codes working properly now, but want to enable a unique, automatically generated code to be sent with any confirmation of a newsletter subscription (it would be something like a 20% off - to be used once). I can follow your instructions for creating the database driven structure, but am having issue with how to generate, transmit and delete the code I wish to send with each newsletter confirmation.

Can you help me with this logic?

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...