Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[add-on] Discount Code (support)


Recommended Posts

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

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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-php-coding.com/discount_code_module_for_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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'] ?? ).

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

  • 2 months later...

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:

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.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_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.

Link to comment
Share on other sites

How doe the customer notification of discount code work. I understand that the customer can enter the discount code into the box on payment information, but in the explanation it says you can use the link for newsletters etc as follows:-

Customer gets a discount by clicking a link or inserting the discount code while checkout. The link containing the discount code (http://www.yourshop.com/?discount_code=12345678) is especially convenient for newsletters sending out and promo campaigns conducting.

Does this mean that you can include this link into your newsletter substituting your shop and discount_code=12345678 with your discount code number as i have tried this link but just get the normal shop page. How does it work ?

Link to comment
Share on other sites

  • 2 weeks later...

To All.

 

I too found this mod to be of great help as I have the ability to give a dealer price so they can purchase off my site instead of directly as they wanted shipping costs immediately.

 

However I had a hard time getting the checkout_confirmation page to show the discount. I install 2.8 and had to go back and add all the mods up to that point.

 

What I eventually found was that in the configuration file the file name ot_discount.php was missing from the MODULE_ORDER_TOTAL_INSTALLED configuration key.

 

Thanks

 

David

Link to comment
Share on other sites

  • 2 weeks later...

Hi All

 

anyone have an idea, how to make this module show the discount with a "-" (minus) sign in the checkout / order confirmation, instead of the standard red font type?

Open catalog/includes/modules/order_total/ot_discount.php and find:

 

        $this->output[] = array('title' => TEXT_DISCOUNT . (!empty($order_info) ? ' (' . $sess_discount_code . ')' : '') . ':',
                               'text' => '<span class="productSpecialPrice">' . $currencies->format($discount, true, $order->info['currency'], $order->info['currency_value']) . '</span>',
                               'value' => $discount);

 

Replace:

 

'<span class="productSpecialPrice">'

With:

'-'

And delete:

 . '</span>'

 

----------------------

 

I find a bug with tax calculation when you select a product discount, the discount is incorrect.

 

If tax is 7%, on discount are missing per product 0.07 €

If tax is 16%, on discount are missing per product 0.16 €

 

Sorry for my poor english :rolleyes:

Bye!

Link to comment
Share on other sites

Using this "fix", tax are ok

 

catalog/includes/modules/order_total/ot_discount.php

 

Find:

if (!empty($order->products[$i]['tax'])){

And replace with:

if ((!empty($order->products[$i]['tax'])) && (strpos($check['discount_values'], '%') == true)){

 

Find:

      if (!empty($discount)) {
       $order->info['total'] -= array_sum($tax_discount);
       $order->info['total'] -= $discount;

Add after:

      if (strpos($check['discount_values'], '%') == true) {
       $discount = $discount + array_sum($tax_discount);			
	}

 

Save the file and upload ;)

 

Regards!!

Link to comment
Share on other sites

Aww, I could never get any coupons to work with my checkout on my older version of OSC, but now that I finally upgraded to 2.3.1 I was hoping it would work.

When I go to the admin section I get this error, and my knowledge in SQL is not good enough to solve it:

 

1054 - Unknown column 'dc.customers_id' in 'field list'

select dc.discount_codes_id, dc.products_id, dc.categories_id, dc.manufacturers_id, dc.excluded_products_id, dc.customers_id, dc.orders_total, dc.order_info, dc.discount_codes, dc.discount_values, dc.minimum_order_amount, dc.expires_date, dc.number_of_orders, dc.number_of_use, dc.number_of_products, dc.status from discount_codes dc order by dc.discount_codes_id desc limit 0, 20

[TEP STOP]

Could anyone give me a hand? :)

 

Alright, I looked a little at the installed SQL, and it appears that the customers_id field is in the other database "customers_to_discount_codes", not "discount_codes"

 

 

CREATE TABLE `customers_to_discount_codes` (

`customers_id` int(11) NOT NULL default '0',

`discount_codes_id` int(11) NOT NULL default '0',

INDEX ( `discount_codes_id` ) ,

KEY `customers_id` (`customers_id`)

);

 

CREATE TABLE `discount_codes` (

`discount_codes_id` int(11) NOT NULL auto_increment,

`products_id` text,

`categories_id` text,

`manufacturers_id` TEXT,

`excluded_products_id` TEXT,

`orders_total` tinyint(1) NOT NULL default '0',

`order_info` TINYINT( 1 ) NOT NULL,

`discount_codes` varchar(8) NOT NULL default '',

`discount_values` varchar(8) NOT NULL default '',

`minimum_order_amount` decimal(15,4) NOT NULL default '0.0000',

`expires_date` date NOT NULL default '0000-00-00',

`number_of_orders` int(4) NOT NULL default '0',

`number_of_use` INT( 4 ) NOT NULL,

`number_of_products` INT( 4 ) DEFAULT '0' NOT NULL,

`status` tinyint(1) NOT NULL default '1',

PRIMARY KEY (`discount_codes_id`)

);

Edited by ardesjo
Link to comment
Share on other sites

Alright, so I fixed my SQL issues by removing "dc.customers_id," from the query in my ot_discount.php file. Not sure if that's going to cause an issue, but it's working for now, with credit cards at least.

 

For PayPal Express I run into the same issue as before. There is nothing calculation the discount before customer gets sent off to PayPal to pay, so the discount is not happening.

I saw someone had a fix for PayPal IPN... but has anyone gotten this to work with PayPal Express?

I use "PayPal Website Payments Pro - Direct Payments" and it requires PayPal Express to be turned on :(

 

Aww, I could never get any coupons to work with my checkout on my older version of OSC, but now that I finally upgraded to 2.3.1 I was hoping it would work.

When I go to the admin section I get this error, and my knowledge in SQL is not good enough to solve it:

 

1054 - Unknown column 'dc.customers_id' in 'field list'

select dc.discount_codes_id, dc.products_id, dc.categories_id, dc.manufacturers_id, dc.excluded_products_id, dc.customers_id, dc.orders_total, dc.order_info, dc.discount_codes, dc.discount_values, dc.minimum_order_amount, dc.expires_date, dc.number_of_orders, dc.number_of_use, dc.number_of_products, dc.status from discount_codes dc order by dc.discount_codes_id desc limit 0, 20

[TEP STOP]

Could anyone give me a hand? :)

 

Alright, I looked a little at the installed SQL, and it appears that the customers_id field is in the other database "customers_to_discount_codes", not "discount_codes"

 

 

CREATE TABLE `customers_to_discount_codes` (

`customers_id` int(11) NOT NULL default '0',

`discount_codes_id` int(11) NOT NULL default '0',

INDEX ( `discount_codes_id` ) ,

KEY `customers_id` (`customers_id`)

);

 

CREATE TABLE `discount_codes` (

`discount_codes_id` int(11) NOT NULL auto_increment,

`products_id` text,

`categories_id` text,

`manufacturers_id` TEXT,

`excluded_products_id` TEXT,

`orders_total` tinyint(1) NOT NULL default '0',

`order_info` TINYINT( 1 ) NOT NULL,

`discount_codes` varchar(8) NOT NULL default '',

`discount_values` varchar(8) NOT NULL default '',

`minimum_order_amount` decimal(15,4) NOT NULL default '0.0000',

`expires_date` date NOT NULL default '0000-00-00',

`number_of_orders` int(4) NOT NULL default '0',

`number_of_use` INT( 4 ) NOT NULL,

`number_of_products` INT( 4 ) DEFAULT '0' NOT NULL,

`status` tinyint(1) NOT NULL default '1',

PRIMARY KEY (`discount_codes_id`)

);

Link to comment
Share on other sites

Alright, so I fixed my SQL issues by removing "dc.customers_id," from the query in my ot_discount.php file. Not sure if that's going to cause an issue, but it's working for now, with credit cards at least.

 

For PayPal Express I run into the same issue as before. There is nothing calculation the discount before customer gets sent off to PayPal to pay, so the discount is not happening.

I saw someone had a fix for PayPal IPN... but has anyone gotten this to work with PayPal Express?

I use "PayPal Website Payments Pro - Direct Payments" and it requires PayPal Express to be turned on :(

 

My fix didn't work. Instead I added the missing "Customers_id" row in the database right after "excluded_products_id".

Works like a charm!

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

 

I'm using this http://addons.oscommerce.com/info/7700/v,23

 

Here's the link of the screenshot:

http://img857.imageshack.us/i/problemo.jpg/

 

I couldn't use the add on,

because the button is not there,

and on the bottom left of ie browser showing there's some error with the page.

 

May I know how could I solve this problem?

 

Thanks a lot!

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...