Jump to content



Photo
* * * - - 3 votes

[add-on] Discount Code (support)


  • Please log in to reply
143 replies to this topic

#21   move_man

move_man
  • Members
  • 1 posts
  • Real Name:Marvin
  • Gender:Male
  • Location:Germany

Posted 06 October 2010 - 06:22

Hy,

is it possible that you einbaust in the module nor the new customers will automatically receive discounts? or there is a discount code discount allows new customers only? or the first time the customer order

Thanks
Marvin

#22   Tesoro Design

Tesoro Design
  • Members
  • 5 posts
  • Real Name:Simon Tesoro
  • Gender:Male
  • Location:Oceanside, CA

Posted 06 October 2010 - 18:47

I have tried searching the forums and have seen that people are having the same issue, I know that they have resolved it because they have moved on to different issues that would only result if they resolved it. I am new to OS Commerce and php. I know html and css, but I need help badly here.

My Issue: I installed everything, followed the directions perfectly, checked 4 times everything. I can even create coupons but when you checkout, there is nowhere to enter the discount code. I am assuming that the reason is because in the directions, it asks you to go to Modules > Order Total > Discount Coupons, but there is no Discount Coupons option in the Order Total area.

Any help with this would be greatly appreciated.

Thanks in Advance,

Simon

#23   GraphicsGuy

GraphicsGuy
  • Members
  • 1,144 posts
  • Real Name:Mike
  • Gender:Male
  • Location:Tennessee

Posted 06 October 2010 - 19:23

I have tried searching the forums and have seen that people are having the same issue, I know that they have resolved it because they have moved on to different issues that would only result if they resolved it. I am new to OS Commerce and php. I know html and css, but I need help badly here.

My Issue: I installed everything, followed the directions perfectly, checked 4 times everything. I can even create coupons but when you checkout, there is nowhere to enter the discount code. I am assuming that the reason is because in the directions, it asks you to go to Modules > Order Total > Discount Coupons, but there is no Discount Coupons option in the Order Total area.

Any help with this would be greatly appreciated.

Thanks in Advance,

Simon


My first thought would be to check to make sure the file:

.../catalog/includes/modules/ot_discount.php

uploaded correctly. If it is missing or got fouled during upload I think it would cause that effect. And if it didn't, I would check the other files that get uploaded to make sure they are ok while you are at it.

Second possibility - make sure you are looking for the right thing in the admin panel. If it is the "Discount Code" contrib that you installed and not the "Discount Coupon" one, then when you go to modules>order total in the admin panel, one of the items on the main part of the screen should be "Discount Code". Select it by clicking once on it. After the page reloads, click the "Install" button. After that completes, set the sort order.

If you installed the "Discount Coupon" contrib, that is a whole other bear and different support thread.
Rule #1:  Without exception, backup your database and files before making any changes to your files or database.
Rule #2:  Make sure there are no exceptions to Rule #1.

#24   GraphicsGuy

GraphicsGuy
  • Members
  • 1,144 posts
  • Real Name:Mike
  • Gender:Male
  • Location:Tennessee

Posted 06 October 2010 - 19:49

Hy,

is it possible that you einbaust in the module nor the new customers will automatically receive discounts? or there is a discount code discount allows new customers only? or the first time the customer order

Thanks
Marvin


Doesn't look like there is feature like that. But here is how I would approach it:

  • Use the new version from the author's website mentioned a few posts above. It has the added feature of letting you limit the number of times per customer it can be used, for example one time per customer.
  • Set up a discount code for use as a new customer discount.
  • Add the new customer discount code and a sentence or two of explanation to the new account setup page. Either make the code real easy to remember or else encourage them to write it down. My way would be to make it real easy since the customer can only use it once anyway.
hth





Rule #1:  Without exception, backup your database and files before making any changes to your files or database.
Rule #2:  Make sure there are no exceptions to Rule #1.

#25   Tesoro Design

Tesoro Design
  • Members
  • 5 posts
  • Real Name:Simon Tesoro
  • Gender:Male
  • Location:Oceanside, CA

Posted 06 October 2010 - 20:53

My first thought would be to check to make sure the file:

.../catalog/includes/modules/ot_discount.php

uploaded correctly. If it is missing or got fouled during upload I think it would cause that effect. And if it didn't, I would check the other files that get uploaded to make sure they are ok while you are at it.

Second possibility - make sure you are looking for the right thing in the admin panel. If it is the "Discount Code" contrib that you installed and not the "Discount Coupon" one, then when you go to modules>order total in the admin panel, one of the items on the main part of the screen should be "Discount Code". Select it by clicking once on it. After the page reloads, click the "Install" button. After that completes, set the sort order.

If you installed the "Discount Coupon" contrib, that is a whole other bear and different support thread.


I did do the Discount Coupons, is there another thread for that here?

#26   Tesoro Design

Tesoro Design
  • Members
  • 5 posts
  • Real Name:Simon Tesoro
  • Gender:Male
  • Location:Oceanside, CA

Posted 06 October 2010 - 20:57

I did do the Discount Coupons, is there another thread for that here?

Actually it says "Discount Coupon Codes". Am I in the right place then? I need help.... lol

#27   GraphicsGuy

GraphicsGuy
  • Members
  • 1,144 posts
  • Real Name:Mike
  • Gender:Male
  • Location:Tennessee

Posted 07 October 2010 - 00:39

That is a different contrib. I think that is a common confusion, so here I will attempt to identify each coupon contribution and its support thread:

Discount Code: http://addons.oscommerce.com/info/7397
That is the contrib that this support thread is about although the author of it doesn't seem to be participating (although as someone noted a few posts up, they have continued refining it and a newer version can be found on their site at http://high-quality-...oscommerce.html .

Discount Coupon Codes: http://addons.oscommerce.com/info/4269
The support thread is here: http://forums.oscomm...t-coupon-codes/

Discount Coupons: http://addons.oscommerce.com/info/300
There doesn't appear to be a support thread. This is a very old contrib (2002) and requires the Credit Class Gift Voucher (CCGV) contrib to be installed first. In 2008 the CCGV contrib absorbed the Discount Coupons contrib, thereby obsoleting this one. - http://addons.oscommerce.com/info/5743 and the support thread is http://forums.oscomm.../page__hl__CCGV

Easy Coupon: http://addons.oscommerce.com/info/4213
The support thread is here: http://forums.oscomm..._Easy%20Coupons

Coupons by Ingo: http://addons.oscommerce.com/info/4148
The support thread is here: http://forums.oscomm...showtopic=41151 (on the German forum)
There are various threads discussing various issues:


Edited by GraphicsGuy, 07 October 2010 - 00:40.

Rule #1:  Without exception, backup your database and files before making any changes to your files or database.
Rule #2:  Make sure there are no exceptions to Rule #1.

#28   dev123

dev123
  • Members
  • 2 posts
  • Real Name:John

Posted 08 October 2010 - 04:46

Hi,

I downloaded the Discount Code contribution and really like it. There is one problem with calculating taxes.
When I have a discount code set up for 10% on a category. It does not calculate the tax portion properly.

Example:

Subtotal: $590.00
Discount: $59.00
5% Tax: $29.50
Total: $560.50

The tax amount should be 26.55 and the Total should be $557.55



Hey everyone,

I had this same issue and it seemed to be with this perticular line of code:

ot_discount.php line 61 (accordinly to 2.4 release)
$tax_discount[$order->products[$i]['tax_description']] += $products_discount * $order->products[$i]['tax'] / 100;

This line of code kept spitting out a warning something about illigal blah blah.. (forgot the exact error)
After using a bunch of print_r statements, I noticed that the array ($tax_discount) was actually empty.

so i updated the above line of code into the following and it worked for me!

ot_discount.php

foreach($order->products[$i]['tax_description'] as $key123 => $value123){
$tax_discount[$key123] += $products_discount * $order->products[$i]['tax'] / 100;
}

Not sure if this was the best and most efficient way, but it worked for me. If anyone has a better example, please feel free to show!

#29   Dj-Viper

Dj-Viper
  • Members
  • 61 posts
  • Real Name:Anne Meinema

Posted 15 October 2010 - 20:39

Hi,

Have installed this contribution, was easy to do. But run into a problem.

How do i use percentages in stead of a fixed price like 1 euro, i want to enter 5 or 10 % but when i do that and add a category i'm getting an error..

Greetings, Dj Viper

#30   GraphicsGuy

GraphicsGuy
  • Members
  • 1,144 posts
  • Real Name:Mike
  • Gender:Male
  • Location:Tennessee

Posted 16 October 2010 - 00:14

Hi,

Have installed this contribution, was easy to do. But run into a problem.

How do i use percentages in stead of a fixed price like 1 euro, i want to enter 5 or 10 % but when i do that and add a category i'm getting an error..

Greetings, Dj Viper


Yeah, the contrib says you can use percentages, but I couldn't get it to accept them either. I didn't get any error messages, it just didn't apply any discount when I entered a percentage discount. I don't know if that has been fixed in the new releases on the authors web site since I haven't upgraded it yet on my site.
Rule #1:  Without exception, backup your database and files before making any changes to your files or database.
Rule #2:  Make sure there are no exceptions to Rule #1.

#31   kevinb456

kevinb456
  • Members
  • 23 posts
  • Real Name:Kevin

Posted 16 October 2010 - 13:44

Yeah, the contrib says you can use percentages, but I couldn't get it to accept them either. I didn't get any error messages, it just didn't apply any discount when I entered a percentage discount. I don't know if that has been fixed in the new releases on the authors web site since I haven't upgraded it yet on my site.


I have the newest version from the authors website (v2.5 from http://high-quality-...oscommerce.html - you have to install the updates, there's no full package.).

The percentages work correctly on mine. I haven't used any previous version (I went straight to v2.5) so I would conclude that this issue has been fixed!

#32   Claud2010

Claud2010
  • Members
  • 3 posts
  • Real Name:Claudius

Posted 21 October 2010 - 16:29

Dear osCommerce Community

frst of all I have to say that this is really a great contribution. I am using it on two different osCommerce installations and it is working great.

On one of my osCmmerce webistes I have installed this Contrib with version 2.5 - and it is simply working perfectly there. The server for this page uses PHP 4.4.9 and MySQL 4.1.22

On my other osCmmerce webiste (which uses MySQL 4.0.25), I have discovered a problem with version 2.5 of this Contrib though - propably due to the MYSQL version on this server, which I unfortunately can´t change though, as the domain is hosted on a shared server and the hosting company won´t do any changes to it.
I have been able to install the updates of the "Discount Codes" Contrib up to version 2.4 ... and it works properly up to that version ... but when I do the update towards version 2.5, there occurs a TEP STOP erroe in the checkout_confirmation.php and the customers can´t complete their order. As version 2.5 includes some nice features such as unlimited usages of discount codes by a customer or including the discount code to the order info, I would like to get version 2.5 running on that server as well.

The TEP STOP error I receive in the checkout_confirmation.php with version 2.5 contains the following error message:

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 'select count(*) as total from discount_codes dc, customers_to_d<br><br>select if(number_of_use = 0, 1, if(a.total < number_of_use, 1, 0)) as result from discount_codes, (select count(*) as total from discount_codes dc, customers_to_discount_codes c2dc where dc.discount_codes_id = c2dc.discount_codes_id and dc.discount_codes = 'e2745e1c' and c2dc.customers_id = '1247') as a where discount_codes = 'e2745e1c' limit 1

I have sourced the reason for this error down to the ot_discount.php file in the folder catalog > includes > modules > order_total.php
The PHP code which causes this error must be somewhere in line 33:

$check_query = tep_db_query(sprintf("select if(number_of_use = 0, 1, if(a.total < number_of_use, 1, 0)) as result from %s, (select count(*) as total from %s dc, %s c2dc where dc.discount_codes_id = c2dc.discount_codes_id and dc.discount_codes = '%s' and c2dc.customers_id = '%s') as a where discount_codes = '%s' limit 1", TABLE_DISCOUNT_CODES, TABLE_DISCOUNT_CODES, TABLE_CUSTOMERS_TO_DISCOUNT_CODES, tep_db_input($sess_discount_code), (int)$customer_id, tep_db_input($sess_discount_code)));

I have tried to resolve this by myself for about nearly two days now - but as I am not being very skilled in PHP and MYSQL I just don´t find a way to resolve this error.

Does anyone have an idea what I would need to do or change in the code above in order to get rid of the error message and make this Contrib to work perfectly in version 2.5 as well on my server? Any hints are being much appreciated.

Thanks in advance,

Claud

#33   GraphicsGuy

GraphicsGuy
  • Members
  • 1,144 posts
  • Real Name:Mike
  • Gender:Male
  • Location:Tennessee

Posted 21 October 2010 - 17:03

I'm not real skilled with php/mysql coding but from my limited exposure to it, I beleive those to line break tags (<br> ) shouldn't be there. If you can find where they are coming from it may solve it. In looking for the source of those line breaks, check places that got editied apply the contrib. In particular (but not limited to), check the lines added to /catalog/includes/database_tables.php .

One possible cause of unintentional liine breaks getting into code is by editing the php code with a rich text editor like MS Word or Open Office Writer. Never use those to edit code of any kind. Simple text editors like Notepad (included in Windows) are good for it. Better yet is a php editor program like the free edition of phpDesigner.
Rule #1:  Without exception, backup your database and files before making any changes to your files or database.
Rule #2:  Make sure there are no exceptions to Rule #1.

#34   kevinb456

kevinb456
  • Members
  • 23 posts
  • Real Name:Kevin

Posted 21 October 2010 - 18:05

Yes, the "<br><br>" looks like you have an extra line placed in the code file. This may be from the original code you copied across or from an extra one you added by accident.

Because this is inside the 'sprintf' function, whatever you add in the appearance of the code is actually counted as part of the string sent to the 'tep_db_query' function.

I also checked the IF() function because I thought that might be the problem - but it is still a valid construct for MySQL v3/4, so thats not a problem.

Also - I'm confused about the following part of the SQL:

select count(*) as total from discount_codes dc, customers_to_d ....

If this valid? Why the space inbetween 'discount_codes' and 'dc', or does the 'dc' mean something special? I haven't seen this before, but its in the PHP code as well, and I have checked my version of 2.5 (which works on my site) and the code is the same so this must be OK, just interested as it looks unusual to me. The subsequent SQL seems to suggest this is the name of a table.

#35   kevinb456

kevinb456
  • Members
  • 23 posts
  • Real Name:Kevin

Posted 21 October 2010 - 18:15

Also just in case it helps anyone, something I had to change to get it to work correctly with my implementation (although this may not affect yours, because I had to move some code to paypal_ipn.php to work with Paypal IPN contribution). Also, I'm not sure if this is specific to v2.5 or just a general thing.

Code placed in checkout_process.php:

if (MODULE_ORDER_TOTAL_DISCOUNT_STATUS == 'true') {
	if (!empty($discount)) {
		$discount_codes_query = tep_db_query("select discount_codes_id from " . TABLE_DISCOUNT_CODES .
			" where discount_codes = '" . tep_db_input($sess_discount_code) . "'");
		$discount_codes = tep_db_fetch_array($discount_codes_query);
		tep_db_perform(TABLE_CUSTOMERS_TO_DISCOUNT_CODES, array('customers_id' => $customer_id,
									'discount_codes_id' => $discount_codes['discount_codes_id']));	
									
		tep_db_query("update " . TABLE_DISCOUNT_CODES . " set number_of_orders = number_of_orders + 1
			where discount_codes_id = '" . (int)$discount_codes['discount_codes_id'] . "'");
		tep_session_unregister('sess_discount_code');
	}
}

I changed the inner if() clause to read:

//if (!empty($discount)) {
	$sess_discount_code = $_SESSION['sess_discount_code'];
	if (!empty($sess_discount_code)) {

because the $discount variable wasn't passed for me (I have no idea where this is meant to come from - its not given in checkout_process.php either!). For me, this caused the discount code not to be updated/checked against the database once the order was processed. I don't know whether this is necessary for all. Possibly you could use the corresponding GET variable if the default code doesn't work for you (is it $_GET['discount_code'] ?? ).

#36   Claud2010

Claud2010
  • Members
  • 3 posts
  • Real Name:Claudius

Posted 21 October 2010 - 19:03

Hi community,

thank you for your so far posted answers. Yes, the <br><br> loooks strange to me as well and actually I don´t have any idea where it comes from ... but I doubt that this is the source of the problem. The reason for the error must actually lie in a difference between MySQL 4.0.25 and MySQL 4.1.22, because the same code (actually the same files) work properly perfect on my server with MySQL 4.1.22, whereas there must be something in this code which is being rejected by MySQL 4.0.25.

Any idea what this could be or how to adapt the code above to MySQL 4.0.25 ?

Thanks in advance

Claud

#37   GraphicsGuy

GraphicsGuy
  • Members
  • 1,144 posts
  • Real Name:Mike
  • Gender:Male
  • Location:Tennessee

Posted 21 October 2010 - 19:15

So the exact files were copied from one server to the other, not simply the same changes made to the existing files, correct? Otherwise, there is still the chance of the line breaks getting added by a rich text editor while making the changes to the one with the older msyql.

If you are positive that the line breaks aren't the problem (I've never seen html line break tags inside sql statements or php conditionals) then the next logical step would be to go to the mysql project website and look at the release notes identifying the changes made between those two versions and compare that with the code. Look for something new in 4.1 that the code is using. I doubt it is something bold. More likel ywould be some incorrect syntax that was allowed in 4.0 but disallowed in 4.1. All of the major projects like PHP, mySQL, JS, etc. are moving towards tighter syntax requirements. (by tighter syntax I mean more adherent to the current theories of best practices in coding)

Edited by GraphicsGuy, 21 October 2010 - 19:16.

Rule #1:  Without exception, backup your database and files before making any changes to your files or database.
Rule #2:  Make sure there are no exceptions to Rule #1.

#38   Claud2010

Claud2010
  • Members
  • 3 posts
  • Real Name:Claudius

Posted 21 October 2010 - 22:47

So the exact files were copied from one server to the other, not simply the same changes made to the existing files, correct? Otherwise, there is still the chance of the line breaks getting added by a rich text editor while making the changes to the one with the older msyql.

If you are positive that the line breaks aren't the problem (I've never seen html line break tags inside sql statements or php conditionals) then the next logical step would be to go to the mysql project website and look at the release notes identifying the changes made between those two versions and compare that with the code. Look for something new in 4.1 that the code is using. I doubt it is something bold. More likel ywould be some incorrect syntax that was allowed in 4.0 but disallowed in 4.1. All of the major projects like PHP, mySQL, JS, etc. are moving towards tighter syntax requirements. (by tighter syntax I mean more adherent to the current theories of best practices in coding)


Yes, the exact files were copied to both servers. So the line breaks are not being the problem.
I had also contacted the developer of this Contrib and he was able to clarify the problem:

"MySQL 4.0.25 doesn't support subqueries. I recommend you to downgrade to version 2.4."

So the problem is actually due to an older version of MySQL on that server. Guess I will have to ask my hoster if he can move my domain to another server that has MySQL 4.1.22 installed as well. That should resolve the problem.

#39   Siremat

Siremat
  • Members
  • 10 posts
  • Real Name:Paul
  • Gender:Male

Posted 06 November 2010 - 22:40

I like the clean setup of this contri, so first my compliments to high-quality-php-coding and Graphics Guy (and others)for the support.

I was wondering if it is possible to show the discount incl. tax.
So it looks like that the customer get's a greater discount amount

Btw, I read about the % problem, I have also tested the 10% discount in version 2.5, and I had a good tax calculation and total amount

#40   sormui

sormui
  • Members
  • 246 posts
  • Real Name:cherry

Posted 04 February 2011 - 20:02

Hi Kevin, thanks for your solution but I would like to set Paypal IPN module set to 'per item' mode. Do you know what modification is required in order to make it work with 'per item'? Thanks!

I've found the solution to making this mod work with Paypal IPN 2.3.4.6 /thumbsup.gif' class='bbc_emoticon' alt=':thumbsup:' />
This may also work with other paypal mods and other discount mods, but you need to check the variable names to be certain.
This is only for use with the Paypal IPN module set to 'aggregate' mode, not 'per item' (although it would work with a bit of modification).


Open \catalog\includes\modules\payment\paypal_ipn.php

Find the code:

        if(MOVE_TAX_TO_TOTAL_AMOUNT == 'True') {
          $parameters['amount'] = number_format(($subtotal + $order->info['tax']) * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
        } else {
          // default
          $parameters['amount'] = number_format($subtotal * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
          $parameters['tax'] = number_format($order->info['tax'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
        }

(make sure this is correct, there's another 'IF' block that looks very similar in a different loop)
Add the following code directly after:

if (isset($order_total['ot_discount'])) {     
	$parameters['discount_amount'] = number_format(($order_total['ot_discount']) * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
}


Done!

The discount will now be included in the paypal payment page, and its event under a special 'discount' heading so your customer can see how much they're saving!


EDIT: I guess you could also set the variable 'discount_amount_cart' instead of 'discount_amount' (see https://cms.paypal.c...d_htmlvariables), but this seems to work so I haven't played around too much. 'discount_amount_cart' is infact for the whole cart so this may work better for aggregate mode.