grucker Posted April 7, 2010 Share Posted April 7, 2010 I have a simple shopping cart with a paypal submit button. I would like to add a box for a discount code and have the refreshed page include a discount from the sub total before adding the postage. Any help? Regards David Quote Link to comment Share on other sites More sharing options...
Jax2 Posted April 7, 2010 Share Posted April 7, 2010 You'll need a new mysql table to keep the codes in, as well as their associated values (such as, for example, -$3.00, -10% ...etc) You'll need to randomly generate a code ID (5 - 10 chars) and insert it into the db along with it's value. Then it's pretty much simple math. Allow the user a place to input the code, search the mysql database for that code, figure out what variable is used for their current total (before postage as you said) and then call the shopping carts checkout page again, using the new value as the subtotal. You can even do fun things like if you want it to be a one time use only coupon, simply add another field such as "status" and update that to equal 1 if they use it, rather than 0 if it hasn't been used yet. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 7, 2010 Share Posted April 7, 2010 Include the field in the form, then while validating the rest of the form, check if the discount code field has a value, and if it does, validate the value. If the value is valid, apply the discount and calculate the new subtotal, otherwise, if the value is invalid, handle it like any other validation error. This is in no way exact, but should give you an idea of the logic you'll need to use. if( isset($_POST['discount_code']) ) { // query the database, or check against an array of valid codes and get the discount percentage if( /*code_is_valid */ ) { $new_subtotal = // calculate new subtotal } else { // set an error, as code is not valid } Quote Link to comment Share on other sites More sharing options...
grucker Posted April 7, 2010 Author Share Posted April 7, 2010 Thanks for the promp replies I only want to put a a simple code ie. discount or member. If I press the buy now button it goes to PAYPAL I have included the function files involved for a more detailed look. Thanks again [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.