Jump to content
kgt

[Contribution] Discount Coupon Codes

Recommended Posts

Hi

 

Ive had a quick search on this topic but cant find anything....

 

I M2.2 (uk).. I have also installed a template which i believe uses STS...

 

The problem:... When i try to coplete an order, on the checkout_payment.php page i enter a discount code (that i have previously crated) and click process, the page just reloads.

 

I have noticed that the URL changes to /checkout_payment.php/error_message/The+coupon+code+you+have+entered+is+not+valid.

even with valid or invalid codes.

 

Also, no error message is displayed on the page. Only in the URL.

 

 

Can anyone help?

 

I've been through the instructions several times and checked for mistakes but to no avail.

 

Cheers,

Mike

Share this post


Link to post
Share on other sites
Hi Kristen

 

Thanks for all your help and your patience - that has done the trick - several test purchases have all gone through smoothly. Excellent

 

J

 

Hi Kristen

 

Sorry to trouble you again - but I have purchases where the customers have used the advertsied discount code - I have received payment notification from Paypal but nothing from my site nor does the order appear in admin under orders - so unless I contact the customer I don't know what he ordered. I normally have trouble with this but could always rely on the order details being on the order page in the admin section.

 

any ideas

 

thks john

Share this post


Link to post
Share on other sites
Sorry to trouble you again - but I have purchases where the customers have used the advertsied discount code - I have received payment notification from Paypal but nothing from my site nor does the order appear in admin under orders - so unless I contact the customer I don't know what he ordered. I normally have trouble with this but could always rely on the order details being on the order page in the admin section.

 

http://forums.oscommerce.com/index.php?sho...184766&st=0


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Ive had a quick search on this topic but cant find anything....

 

I M2.2 (uk).. I have also installed a template which i believe uses STS...

 

The problem:... When i try to coplete an order, on the checkout_payment.php page i enter a discount code (that i have previously crated) and click process, the page just reloads.

 

I have noticed that the URL changes to /checkout_payment.php/error_message/The+coupon+code+you+have+entered+is+not+valid.

even with valid or invalid codes.

 

Also, no error message is displayed on the page. Only in the URL.

Can anyone help?

 

I've been through the instructions several times and checked for mistakes but to no avail.

 

You see no error message because of the template. For some reason, most people who create templates seem content to leave out some of the default OSC error messaging.

 

The invalid coupon message will be displayed when:

1) The code is not found in the table

2) The start date is after today

3) The end date is before today

 

In most cases this happens, the start or end date is before/after today. This can happen because the coupon admin expects dates in the format specified by your admin/includes/languages/english.php and you've entered the date in a different format.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites

I am new to this and have been trying to add a coupon code to my commerece for 2 days and have read and re-read everything and i must be missing something?? Is there any place to direct a complete newbie on how to add a coupon code?

Share this post


Link to post
Share on other sites
I am new to this and have been trying to add a coupon code to my commerece for 2 days and have read and re-read everything and i must be missing something?? Is there any place to direct a complete newbie on how to add a coupon code?

 

The manual? If you didn't install the admin correctly you can find it in admin/includes/languages/english/coupons_manual.html.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
The statement require_ONCE is supposed to not include the file again if it's already been included. Not sure why you seem to be having problems - no one else is. I cannot imagine it's due to any other contribution, but who knows? ;)

 

I think you'd be okay removing that line. The order class should include the discount coupons class file, and the code that needs the discount coupons class also needs the order class. So the require_once in ot_discount_coupon.php should be completely unnecessary and I don't think you'll run into problems by removing it.

 

 

 

Thank you for figuring out this problem! Site was giving double discount until I removed that line!

THanks.!

Share this post


Link to post
Share on other sites
You see no error message because of the template. For some reason, most people who create templates seem content to leave out some of the default OSC error messaging.

 

The invalid coupon message will be displayed when:

1) The code is not found in the table

2) The start date is after today

3) The end date is before today

 

In most cases this happens, the start or end date is before/after today. This can happen because the coupon admin expects dates in the format specified by your admin/includes/languages/english.php and you've entered the date in a different format.

 

 

Thanks a lot. It was the date that was the issues. All is working now.

 

But, how can i include the error message into the template?

 

Thanks,

Mike

Share this post


Link to post
Share on other sites
For some reason it went into my Junk folder. I just sent you a reply.

 

 

Hi Kristen,

 

Ok, I did some more testing this morning, this is what I have found. If there is a minimum dollar amount then the discount works, if there is a maximum dollar amount the calculation is wrong.

 

Steve

Share this post


Link to post
Share on other sites

Serious problem. When a customer first uses a coupon, it works great.

 

However, if the same customer goes back to the store to checkout, the coupon discount is being remembered and the discount is automatically being applied, which is not good. Also, if the customer reenters the coupon code during checkout, then the amount discounted is doubled. The customer can also enter another discount code and take additional discounts.

 

What is wrong? Anyone else having this problem? HELP!

Share this post


Link to post
Share on other sites

animatco is right.

 

If you have a max dollar ammount set, the calulation is WAY off.

 

It is calculating the discount on the MAX ammount.

 

I was giving a $12 discount when it should have been $2

 

 

Any help fixing this would be very much appreciated.

Share this post


Link to post
Share on other sites
animatco is right.

 

If you have a max dollar ammount set, the calulation is WAY off.

 

It is calculating the discount on the MAX ammount.

 

I was giving a $12 discount when it should have been $2

Any help fixing this would be very much appreciated.

 

The documentation should be changed to more accurately describe what the max_order field is. It's intended to work exactly as you're describing. If the max amount is set, the discount will be applied to the max_order amount.

 

Enter the maximum order subtotal to which this discount should be applied. You may use this field to set an upper limit on discounts the amount to which the discount will always be applied. If an order subtotal is greater or less than the Max Order field, then the Max Order field will be used as the basis for calculating the discount. If you do not enter a value, or you enter 0, the discount will be applied to the entire order subtotal amount. This field cannot be edited for existing coupons.

 

It was added for the fixed discounts - %25 of $20 is always $5, so that's how you can have a fixed discount, whether the order total is $15 or $30. The max_order field is set to $20 so the discount is always applied to $20.

 

It does need a better name - any suggestions?


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Hi Kristen,

 

Ok, I did some more testing this morning, this is what I have found. If there is a minimum dollar amount then the discount works, if there is a maximum dollar amount the calculation is wrong.

 

Steve

 

I think you may be tying to use that field in a way that seems obvious, but it's not the way the field actually works. See my reply:

 

http://forums.oscommerce.com/index.php?sho...id=949902


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Serious problem. When a customer first uses a coupon, it works great.

 

However, if the same customer goes back to the store to checkout, the coupon discount is being remembered and the discount is automatically being applied, which is not good. Also, if the customer reenters the coupon code during checkout, then the amount discounted is doubled. The customer can also enter another discount code and take additional discounts.

 

What is wrong? Anyone else having this problem? HELP!

 

There's only one field in the order object to hold the coupon information. I'm not sure how you're managing to get it to apply twice. Are you seeing two order total lines or just one line with a doubled amount? What version are you using? Make sure you made the last change to checkout_process.php, which should be almost the last line in the file:

 

//kgt - discount coupons
 tep_session_unregister('coupon');
//end kgt - discount coupons


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites

I just wanted to drop in and give two thumbs up for this contribution. The installation was simple and straightforward and everything appears to be working exactly as expected.

 

Excellent work!


Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Share this post


Link to post
Share on other sites

Last night's enthusiasm has been tempered somewhat.

 

I set up one coupon for five dollars off any order of $10 or more. The discount is 5, the min order is 10.

 

If I put one average item in the cart, say in the $20-30 range, the discount works ok, $4.99-$5.01.

 

But if I have a subtotal of exactly $10.00 from 8 items priced at $1.25 each, the discount is $5.04.

 

If I add in an $8.95 product to that cart, the discount goes down to $4.98.

 

If I have a cart with 40 products at $1.25, 2 at $4.99, 2 at $0.01, and 1 at $23.95 (subtotal $83.95), the discount is $3.73.

 

The first three scenarios are only off by a few cents, but that last one is absurd.

 

Am I doing something wrong?


Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Share this post


Link to post
Share on other sites
Last night's enthusiasm has been tempered somewhat.

 

I set up one coupon for five dollars off any order of $10 or more. The discount is 5, the min order is 10.

 

If I put one average item in the cart, say in the $20-30 range, the discount works ok, $4.99-$5.01.

 

But if I have a subtotal of exactly $10.00 from 8 items priced at $1.25 each, the discount is $5.04.

 

If I add in an $8.95 product to that cart, the discount goes down to $4.98.

 

If I have a cart with 40 products at $1.25, 2 at $4.99, 2 at $0.01, and 1 at $23.95 (subtotal $83.95), the discount is $3.73.

 

The first three scenarios are only off by a few cents, but that last one is absurd.

 

Am I doing something wrong?

 

It has to do with the fact that OSC rounds at the same time it calculates tax on items. This means rounding happens at each stage of calculation - which is a common source of math errors. If you do not display your prices with taxes, you can remove the tax calculation functions to alleviate this.

 

In includes/classes/discount_coupon.php line 111 replace the existing calculate_discount() function with this:

 

		function calculate_discount( $product, $product_count ) {
		//if there's a maximum order amount to apply the discount to, determine the percentage of this product's final price we should apply the discount to
		//$max_applied_percentage = ( $this->coupon['coupons_max_order'] == 0 ? '1.00' : $this->coupon['coupons_max_order'] / ( tep_add_tax( $product['final_price'] * $product['qty'], $product['tax'] ) * $product_count ) );
		$max_applied_percentage = ( $this->coupon['coupons_max_order'] == 0 ? '1.00' : $this->coupon['coupons_max_order'] / ( $product['final_price'] * $product['qty'] ) * $product_count );
	  //$applied_discount = tep_add_tax( $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'], $product['tax'] ) * $product['qty'];
	  $applied_discount = $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'] * $product['qty'];
	  //don't allow the discount amount to be more than the product price
	  //if( $applied_discount > ( tep_add_tax( $product['final_price'], $product['tax'] ) * $product['qty'] ) ) $applied_discount = tep_add_tax( $product['final_price'], $product['tax'] ) * $product['qty'];
	  if( $applied_discount > ( $product['final_price'] * $product['qty'] ) ) $applied_discount = $product['final_price'] * $product['qty'];
		return $applied_discount;
	}


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
It has to do with the fact that OSC rounds at the same time it calculates tax on items. This means rounding happens at each stage of calculation - which is a common source of math errors. If you do not display your prices with taxes, you can remove the tax calculation functions to alleviate this.

 

Thanks for the quick reply, unfortunately the new function produces unruly results (a discount of $50.00 off the cart with a subtotal of $83.95).

 

I was intending to use this module primarily for fixed amount coupons and it seems like it would need to be re-wired somewhat to work the way I was hoping it would.

 

The structure I'm thinking of is to be able to choose whether a coupon is fixed amount or percentage. If it's a percentage the existing calculations can be performed, but if it's a fixed amount then that amount is subtracted from the subtotal.

 

Have you looked into this already and/or is there already a discount module that works that way?


Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Share this post


Link to post
Share on other sites
Thanks for the quick reply, unfortunately the new function produces unruly results (a discount of $50.00 off the cart with a subtotal of $83.95).

 

It's because I made a typo on the $max_applied_percentage line. Try this function:

 

		function calculate_discount( $product, $product_count ) {
		//if there's a maximum order amount to apply the discount to, determine the percentage of this product's final price we should apply the discount to
		//$max_applied_percentage = ( $this->coupon['coupons_max_order'] == 0 ? '1.00' : $this->coupon['coupons_max_order'] / ( tep_add_tax( $product['final_price'] * $product['qty'], $product['tax'] ) * $product_count ) );
		$max_applied_percentage = ( $this->coupon['coupons_max_order'] == 0 ? '1.00' : $this->coupon['coupons_max_order'] / ( $product['final_price'] * $product['qty'] * $product_count ) );
	  //$applied_discount = tep_add_tax( $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'], $product['tax'] ) * $product['qty'];
	  $applied_discount = $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'] * $product['qty'];
	  //don't allow the discount amount to be more than the product price
	  //if( $applied_discount > ( tep_add_tax( $product['final_price'], $product['tax'] ) * $product['qty'] ) ) $applied_discount = tep_add_tax( $product['final_price'], $product['tax'] ) * $product['qty'];
	  if( $applied_discount > ( $product['final_price'] * $product['qty'] ) ) $applied_discount = $product['final_price'] * $product['qty'];
		return $applied_discount;
	}

 

You should see much more accurate results with this.

 

I was intending to use this module primarily for fixed amount coupons and it seems like it would need to be re-wired somewhat to work the way I was hoping it would.

 

The structure I'm thinking of is to be able to choose whether a coupon is fixed amount or percentage. If it's a percentage the existing calculations can be performed, but if it's a fixed amount then that amount is subtracted from the subtotal.

 

Have you looked into this already and/or is there already a discount module that works that way?

 

As it states in the manual, this contribution is NOT appropriate for many people who desire fixed discounts. It applies a percentage discount only, even for "fixed" discounts. Fixed discounts are problamatic in any order calculation that uses multiple tax rates. If you read the manual, or the rest of this thread, you can find more discussion on fixed discounts and why they can be difficult to deal with when you're applying discounts before the whole order has been totalled. CCGV performs calculations after the order is totalled. This allows for reliable fixed discounts.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
It's because I made a typo on the $max_applied_percentage line. Try this function:

You should see much more accurate results with this.

 

As it states in the manual, this contribution is NOT appropriate for many people who desire fixed discounts. It applies a percentage discount only, even for "fixed" discounts. Fixed discounts are problamatic in any order calculation that uses multiple tax rates. If you read the manual, or the rest of this thread, you can find more discussion on fixed discounts and why they can be difficult to deal with when you're applying discounts before the whole order has been totalled. CCGV performs calculations after the order is totalled. This allows for reliable fixed discounts.

 

Actually read the manual? Jeez.... :)

 

Thanks for the help!


Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Share this post


Link to post
Share on other sites

I think I may have found a way to get a reliable fixed amount discount:

 

function calculate_discount( $product, $product_count ) {
	   if ( $this->coupon['coupons_type'] == 'fixed') {

	   $applied_discount = $this->coupon['coupons_discount_percent'] * $this->coupon['coupons_max_order'] / $product_count;

  } else {

		$max_applied_percentage = ( $this->coupon['coupons_max_order'] == 0 ? '1.00' : $this->coupon['coupons_max_order'] / ( $product['final_price'] * $product['qty'] * $product_count ) );

		$applied_discount = $product['final_price'] * $max_applied_percentage * $this->coupon['coupons_discount_percent'] * $product['qty'];

		if( $applied_discount > ( $product['final_price'] * $product['qty'] ) ) $applied_discount = $product['final_price'] * $product['qty'];

		}
		return $applied_discount;
	}

 

I added one field to the 'discount_coupons' table, "coupons_type". If it's set as 'fixed' then it calculates a set amount, otherwise it calculates a percentage. It seems to be working ok.


Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×