Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Discount Coupon Codes


kgt

Recommended Posts

Is there any way possible to add the data entry of the coupon code in the shopping cart?

 

I would like to give 100% discount on some things, enabling the customer to bypass the payment page.

 

Thanks

 

 

Yes, but not without fairly significant changes. The shopping cart is 100% different from the order process. It's an ENTIRELY different set of code.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

For anyone else who may experience this problem, I did receive a fix for it from Kristen. (Thanks Kristen!!) :thumbsup:

 

Tracy,

 

The total you're getting is actually 8.8817841970013E-16, which is 0.000000000000000088817841970013 (I think I counted the right number of zeros). This is because of the nature of how fixed discounts are calculated and the fact that computers often have a very difficult time internally representing decimal numbers. For example, it is not possible for a computer to store 1/10 exactly unless it stores it as a string of text. The result of 1/10 (.1) is as impossible for a computer to store without some rounding as it is impossible for us to display the result of 1/3 (.333333333…) without some rounding. Unfortunately, it looks like the total is being incorrectly rounded as 8.88 instead of 0.00 because the osCommerce rounding function doesn't take into account that there are numbers needing to be rounded that have an exponent.

 

The problem looks like it's in the tep_round() function in includes/functions/general.php. Try replacing it with the following function:

 

 
 function tep_round($number, $precision) {
if($exponent_loc = strpos(strtolower($number), 'e-')) { //there's an exponent
  $exponent_value = substr($number, $exponent_loc + 2);
  $base_value = substr($number, 0, $exponent_loc);
  $amount_to_truncate = strlen($base_value) - $exponent_value;
  if($amount_to_truncate < 0) $truncated_base_value = 0;
  else $truncated_base_value = substr($base_value, 0, $amount_to_truncate);
  $number = $truncated_base_value * ( 1 / (10 * $exponent_value));
}
if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.')+1)) > $precision)) {
  $number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1);

  if (substr($number, -1) >= 5) {
	if ($precision > 1) {
	  $number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision-1) . '1');
	} elseif ($precision == 1) {
	  $number = substr($number, 0, -1) + 0.1;
	} else {
	  $number = substr($number, 0, -1) + 1;
	}
  } else {
	$number = substr($number, 0, -1);
  }
}

return $number;
 }

 

 

Hi Kristen,

 

Well - I'm baffled at this point. I setup a coupon that would discount $21.75 from an order provided one of three products was in the order - just using the basic product exclusion and coupon setup in the admin, no special coding.

 

The concept is to provide a free 2 oz product with free shipping.

 

But - somewhere the math goes goofy:

 

Here is what the customer sees:

 

Product Total $14.75

Discount applied: -$21.70

Sub-Total: -$6.95

Shipping: $6.95

Total: $8.88

 

Any idea why it isn't giving a $0.00 balance for the total? I'm not sure which bit of code to research for this one :huh:

 

Thanks! :blush:

~Tracy
 

Link to comment
Share on other sites

Hi,

 

I just installed 3.3 and things were ok if I shipped by weight. When I use a Price table to lookup shipping charges, if the coupon (% discount) lowers the cost of the items "down" to the next table level, when i click continue, OS Commerce goes "back" to the shipping page with a "bar" accross the top of the screen telling me my shipping charges have changed. When I click continue I get the payment selection and coupon page again. I cant get out of the "loop"

 

Anyone have any ideas?

 

Tom

Link to comment
Share on other sites

If this is somewhere in the 76 pages of posts, let me know and I'll go hunt it down.

 

My goal is to offer 50 & 100 $ gift cards. I thought I could do this by offering a fixed discount (50) on a min value of 50 and a max value of 50. The problem is that depending on the final value I get results of a discount (credit) of anything from 45 to other odd amounts.

 

The problem amplifies with the 100 credit as well. 100 discount comes up as $92 discount

 

Is this part of the rounding issue?

 

Are you going to tell me that I should use the CCGV module?

 

Thanks much!

 

--Brett

Link to comment
Share on other sites

Hi,

 

I just installed 3.3 and things were ok if I shipped by weight. When I use a Price table to lookup shipping charges, if the coupon (% discount) lowers the cost of the items "down" to the next table level, when i click continue, OS Commerce goes "back" to the shipping page with a "bar" accross the top of the screen telling me my shipping charges have changed. When I click continue I get the payment selection and coupon page again. I cant get out of the "loop"

 

Anyone have any ideas?

 

Tom

 

 

Did you make the changes to includes/modules/shipping/table.php?

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

If this is somewhere in the 76 pages of posts, let me know and I'll go hunt it down.

 

My goal is to offer 50 & 100 $ gift cards. I thought I could do this by offering a fixed discount (50) on a min value of 50 and a max value of 50. The problem is that depending on the final value I get results of a discount (credit) of anything from 45 to other odd amounts.

 

The problem amplifies with the 100 credit as well. 100 discount comes up as $92 discount

 

Is this part of the rounding issue?

 

Are you going to tell me that I should use the CCGV module?

 

Thanks much!

 

--Brett

 

 

It sounds like you have an older version. If so, try the newest version. There are some calculation changes between version 2 and 3 that makes 3 much more reliable.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Hi,

 

Just made sure I had saved the changes. Yes I had made the changes.

 

Tom

 

 

If you do not want this check to even occur, you can comment out line 85 of includes/classes/discount_coupon.php:

 

//if( discount_coupon::is_recalc_shipping() ) tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( ENTRY_DISCOUNT_COUPON_SHIPPING_CALC_ERROR ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method

 

Otherwise, it looks like it actually depends on "Display subtotal with applied discount?" being set to true? Do you have this set to false?

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Hi,

 

I just installed this mod yesterday, and now I get doubled subtotals on all orders. Anybody else experienced this? As far as I know I added all the code correctly.

 

Thanks.

 

 

Double check the changes made to includes/classes/order.php. Most calculation and display problems originate from missing/duplicate code in that file.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Please review the installation instructions for admin/includes/boxes/catalog.php.

 

This is what I have:

$contents[] = array('text' => '<a href="' . tep_href_link(FILENAME_CATEGORIES, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_CATEGORIES_PRODUCTS . '</a><br>' .

'<a href="' . tep_href_link(FILENAME_PRODUCTS_ATTRIBUTES, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_CATEGORIES_PRODUCTS_ATTRIBUTES . '</a><br>' .

'<a href="' . tep_href_link(FILENAME_MANUFACTURERS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_MANUFACTURERS . '</a><br>' .

'<a href="' . tep_href_link(FILENAME_REVIEWS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_REVIEWS . '</a><br>' .

'<a href="' . tep_href_link(FILENAME_SPECIALS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_SPECIALS . '</a><br>' .

//kgt - discount coupons

'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a><br>'

'<a href="' . tep_href_link(FILENAME_DISCOUNT_COUPONS, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_DISCOUNT_COUPONS . '</a>' );

/***************

'<a href="' . tep_href_link(FILENAME_PRODUCTS_EXPECTED, '', 'NONSSL') . '" class="menuBoxContentLink">' . BOX_CATALOG_PRODUCTS_EXPECTED . '</a>' );

***************/

//end kgt - discount coupons

Link to comment
Share on other sites

I could use a little help.

 

I have installed Discount Coupon Codes 3.3 + bug fixes

Windows Server

PHP 5.2

 

Once I installed the Contribution and added a New Coupon, everything appeared to be great. However, when I clicked on the hyperlink 'online catalog' in the top right hand corner of the /admin screen to take me to my web site it opened a version of my admin Screen in a very basic/ diluted way. It was a mix between the /admin index.php, and my catalog index.php. If I click the refresh button many times it would eventually open the catalog Index.php file cleanly.

 

 

However, as I would walk a test order through it would give me various errors and fatal errors, but if I clicked refresh once it would usually clean that up. And after alot of refreshing and errors I could walk the order through. Once the coupon had been used it I would not expreince this problem anymore. But if I completed a New Coupon, I would get the same issue all over again. Even if I typed my URL into the address bar I would get the same issue on my index.php file.

 

I have moved my Catalog folder to my root folder, would this cause any issues? I also contacted my hosting company, but they are never really any help.

 

Can anyone point me in the right direction with this issue? Or has anyone experienced this issue.

Link to comment
Share on other sites

It sounds like you have an older version. If so, try the newest version. There are some calculation changes between version 2 and 3 that makes 3 much more reliable.

 

Excellent diagnosis, and excellent code.

 

I upgraded from 2.1 striaght to 3.3. I had all of the update instructions available, so when it said to replace A with B, and then another version said to replace B with C, I just went from A to C. It took a bit to get it all straight in my head, but once I started updating code it went REALLY smoothly.

 

Thanks for the great code, oh, and the fixed discounts work GREAT! Thanks for the module.

 

--Brett

Link to comment
Share on other sites

I just did a first time install. I used the version 3.3 download. I didn't use the 2 later fixes listed on that screen as I wasn't sure that they were required. The install went relatively smooth. I did get one of the common sql errors that a lot of people get.... something with the '-20,20' bit. But a quick read of the common problems got that fixed. So now I've got the module set up and created a coupon. That all went smoothly. Unfortunately when I went to do a test transaction, when I enter the discount code and click the Continue button I get a red bar across the top of the store with the message "The coupon code you have entered is not valid". I've tried several times, I'm even copying and pasting the code from the coupon creation screen. But I constantly get that message.

 

I searched through as much of the 76 pages of posts here as I could and didn't actually find anyone with this basic problem. Is there something that I can do to figure out what is going wrong? I've created another coupon and changed some of the values from the first one, but I get the same error.

 

FWIW, my coupon has the following values:

Coupon Code: auto generated 6 character entry

Description: Test Coupon

Discount Amount: 0.1500

Discount Type: Percentage Discount

Start Date: 9/22/07

End Date: 9/24/07

Max Use: 1

Min Order: 0

Min Order Type: Price Total

Number Available: 100 (had this blank originally)

 

Thanks for any help anyone can provide.

 

-Chris

Link to comment
Share on other sites

Change lines 72-78 in includes/classes/discount_coupon.php from this:

 

		$check_user_query = tep_db_query($sql = 'SELECT dc2z.geo_zone_id
											  FROM '.TABLE_DISCOUNT_COUPONS_TO_ZONES.' dc2z
											  LEFT JOIN '.TABLE_ZONES_TO_GEO_ZONES.' z2g
												USING( geo_zone_id )
											  WHERE ( z2g.zone_id='.$delivery['zone_id'].' or z2g.zone_id = 0 or z2g.zone_id IS NULL )
												AND ( z2g.zone_country_id='.$delivery['country_id'].' or z2g.zone_country_id = 0 )
												AND dc2z.coupons_id="'.tep_db_input( $code ).'"' );

 

to this:

 

		$check_user_query = tep_db_query($sql = 'SELECT dc2z.geo_zone_id
											  FROM '.TABLE_DISCOUNT_COUPONS_TO_ZONES.' dc2z
											  LEFT JOIN '.TABLE_ZONES_TO_GEO_ZONES.' z2g
												USING( geo_zone_id )
											  WHERE ( z2g.zone_id = '.(int)$delivery['zone_id'].' or z2g.zone_id = 0 or z2g.zone_id IS NULL )
												AND ( z2g.zone_country_id='.(int)$delivery['country_id'].' or z2g.zone_country_id = 0 )
												AND dc2z.coupons_id="'.tep_db_input( $code ).'"' );

I have tried this but now the coupon codes don't work please help

Edited by tabTalk
Link to comment
Share on other sites

I installed this and keep getting the following error.

 

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'or z2g.zone_id = 0 or z2g.zone_id IS NULL ) ' at line 5

 

Can anyone help me with what is wrong?

 

 

Thanks

Link to comment
Share on other sites

I installed this and keep getting the following error.

 

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'or z2g.zone_id = 0 or z2g.zone_id IS NULL ) ' at line 5

 

Can anyone help me with what is wrong?

Thanks

 

I just figured out the problem and it is now fixed. Thanks for the contribution

Link to comment
Share on other sites

I just did a first time install. I used the version 3.3 download. I didn't use the 2 later fixes listed on that screen as I wasn't sure that they were required. The install went relatively smooth. I did get one of the common sql errors that a lot of people get.... something with the '-20,20' bit. But a quick read of the common problems got that fixed. So now I've got the module set up and created a coupon. That all went smoothly. Unfortunately when I went to do a test transaction, when I enter the discount code and click the Continue button I get a red bar across the top of the store with the message "The coupon code you have entered is not valid". I've tried several times, I'm even copying and pasting the code from the coupon creation screen. But I constantly get that message.

 

I searched through as much of the 76 pages of posts here as I could and didn't actually find anyone with this basic problem. Is there something that I can do to figure out what is going wrong? I've created another coupon and changed some of the values from the first one, but I get the same error.

 

FWIW, my coupon has the following values:

Coupon Code: auto generated 6 character entry

Description: Test Coupon

Discount Amount: 0.1500

Discount Type: Percentage Discount

Start Date: 9/22/07

End Date: 9/24/07

Max Use: 1

Min Order: 0

Min Order Type: Price Total

Number Available: 100 (had this blank originally)

 

Thanks for any help anyone can provide.

 

-Chris

 

Perhaps try making a coupon with the minimum number of fields filled in eg no start & end date, no max use just leave them blank

,

Link to comment
Share on other sites

The contrib documentation says the discount will be applied before tax, BUT....

 

I see many recent posts that indicate the discount is being applied AFTER tax. Since this is what I'm looking for... a gift certificate that will apply as a payment, not a change to the original sale calculation. Is there a certain version of the contribution I should be downloading? Or certain 'errors' I should make during the installation?

Link to comment
Share on other sites

The contrib documentation says the discount will be applied before tax, BUT....

 

I see many recent posts that indicate the discount is being applied AFTER tax. Since this is what I'm looking for... a gift certificate that will apply as a payment, not a change to the original sale calculation. Is there a certain version of the contribution I should be downloading? Or certain 'errors' I should make during the installation?

 

 

It's more like fudging. Unless you're giving a 100% discount, the tax will always be calculated against the discounted price. People who try to use these as gift certificates (applied after tax) are fudging and accepting the small errors that can crop up trying to do it that way. Or they just don't understand what the difference is.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

I just did a first time install. I used the version 3.3 download. I didn't use the 2 later fixes listed on that screen as I wasn't sure that they were required. The install went relatively smooth. I did get one of the common sql errors that a lot of people get.... something with the '-20,20' bit. But a quick read of the common problems got that fixed. So now I've got the module set up and created a coupon. That all went smoothly. Unfortunately when I went to do a test transaction, when I enter the discount code and click the Continue button I get a red bar across the top of the store with the message "The coupon code you have entered is not valid". I've tried several times, I'm even copying and pasting the code from the coupon creation screen. But I constantly get that message.

 

 

"The coupon code you have entered is not valid" message displays when:

 

1. No coupons could be found with a date range that matches today

2. No coupon could be found that matches the given code

3. A customer-level exclusion was found

 

Double check none of the above is true. Also TRIPLE CHECK that your dates are REAL DATES. Make sure they're "9/22/2007" and not "9/22/0007".

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...