Jump to content
kgt

[Contribution] Discount Coupon Codes

Recommended Posts

Just upgraded to 3.0. Admin works fine, Created test coupon. When I enter the coupon code, I get the mySQl 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

 

SELECT dc2z.geo_zone_id FROM discount_coupons_to_zones dc2z LEFT JOIN zones_to_geo_zones z2g USING( geo_zone_id ) WHERE ( z2g.zone_id= or z2g.zone_id = 0 or z2g.zone_id IS NULL ) AND ( z2g.zone_country_id= or z2g.zone_country_id = 0 ) AND dc2z.coupons_id="M2EZTC"

 

Where did I go wrong?

 

Martin >_<

Share this post


Link to post
Share on other sites
Just upgraded to 3.0. Admin works fine, Created test coupon. When I enter the coupon code, I get the mySQl 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

 

SELECT dc2z.geo_zone_id FROM discount_coupons_to_zones dc2z LEFT JOIN zones_to_geo_zones z2g USING( geo_zone_id ) WHERE ( z2g.zone_id= or z2g.zone_id = 0 or z2g.zone_id IS NULL ) AND ( z2g.zone_country_id= or z2g.zone_country_id = 0 ) AND dc2z.coupons_id="M2EZTC"

 

Where did I go wrong?

 

Martin >_<

 

You probably don't have your zones set up correctly. Either get them fixed, or try replacing lines 69-75 of includes/classes/discount_coupon.php with 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 ).'"' );


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
You probably don't have your zones set up correctly. Either get them fixed, or try replacing lines 69-75 of includes/classes/discount_coupon.php with 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 ).'"' );

 

Your suggested replacement code worked, and fixed the problem.

 

My zones weren't touched; they worked fine prior to and after your code replacement.

 

Care to explain?

 

Thanx for this very nice contrib.

 

Martin

Share this post


Link to post
Share on other sites

Need Help!

 

I installed this module (its GREAT!) and i'm using a template on my shop. When a user enters an invalid code, i don't see the error message ANYWHERE for some reason. How is this configured? Where is it supposed to show?

 

Does anyone know a way that i can have the error message popup like a message box? that would be great.

 

Thanks for you help

Share this post


Link to post
Share on other sites
Need Help!

 

I installed this module (its GREAT!) and i'm using a template on my shop. When a user enters an invalid code, i don't see the error message ANYWHERE for some reason. How is this configured? Where is it supposed to show?

 

Does anyone know a way that i can have the error message popup like a message box? that would be great.

 

Please see the common problems section for help with this.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Please see the common problems section for help with this.

 

 

kgt - Thanks, i did that. It worked.. HOWEVER, my entire template looks extremely wierd.. Everything on the side has been pushed down. But the error does show now, anyway to fix this? Or perhaps have the error in a popup message?

 

Thanks for your help.

 

Josh

Share this post


Link to post
Share on other sites
kgt - Thanks, i did that. It worked.. HOWEVER, my entire template looks extremely wierd.. Everything on the side has been pushed down. But the error does show now, anyway to fix this? Or perhaps have the error in a popup message?

 

 

The way to fix this will be completely dependent on your template. I suggest posting to the general questions forum for help with HTML and layout. That's off-topic for this thread.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites

Hello:

 

I just installed Discount Coupons 3 on a site in development. I briefly was testing the system using version 2.0, but deleted the two database files and started fresh by manually editing my template-based site to version 3. (I added the seven new database tables manually using PhpMyAdmin.)

 

I'm getting this error message when I proceed to checkout_process.php:

 

1062 - Duplicate entry '27' for key 1

insert into discount_coupons_to_orders (coupons_id, orders_id) values ('', '27')

[TEP STOP]

It appears that the value for the coupons_id is not being properly passed on this line of checkout_process.php:

 

//kgt - discount coupons
 if( tep_session_is_registered( 'coupon' ) && is_object( $order->coupon ) ) {
   $sql_data_array = array( 'coupons_id' => $order->coupon->code,
                            'orders_id' => $insert_id );
   tep_db_perform( TABLE_DISCOUNT_COUPONS_TO_ORDERS, $sql_data_array );
 }
 //end kgt - discount coupons  

What did I do incorrectly? Can this be corrected?

Share this post


Link to post
Share on other sites
I'm getting this error message when I proceed to checkout_process.php:

 

1062 - Duplicate entry '27' for key 1

insert into discount_coupons_to_orders (coupons_id, orders_id) values ('', '27')

[TEP STOP]

It appears that the value for the coupons_id is not being properly passed on this line of checkout_process.php:

 

 

Try re-uploading includes/classes/discount_coupon.php from the newest install file. If that doesn't fix it, let me know and I'll take a closer look tomorrow.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Try re-uploading includes/classes/discount_coupon.php from the newest install file. If that doesn't fix it, let me know and I'll take a closer look tomorrow.

 

Thanks for the prompt feedback. That tip didn't work, but I think the problem was that I had elements of version 2.0 mingled in with the new code. I restored the whole site from backups I'd made before installation and tried again, and now the coupon system works properly.

 

I have another question, much less important, though: I've redeemed a few coupons in testing, but the coupons report ("Discount Coupon Codes Usage Information") doesn't show the "number used" incrementing with each use. Is it supposed to? My test coupon has values of 0 for Max Use and Number Available.

 

Anyway, it's a great add-on, just what my client was looking for. Thanks so much.

 

Mike

Edited by mbrailer

Share this post


Link to post
Share on other sites
I have another question, much less important, though: I've redeemed a few coupons in testing, but the coupons report ("Discount Coupon Codes Usage Information") doesn't show the "number used" incrementing with each use. Is it supposed to? My test coupon has values of 0 for Max Use and Number Available.

 

 

If it's properly inserting into the discount_coupons_to_orders table, you should be seeing the counts rise. Take a look in that table, if it's empty, you still have a problem on checkout_process.php.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites

I got the following message on checkout_shipping.php:

 

Warning: Missing argument 2 for discount_coupon() in /xxx/includes/classes/discount_coupon.php on line 18

 

Warning: Cannot modify header information - headers already sent by (output started at /xxx/includes/classes/discount_coupon.php:18) in /xxx/includes/functions/general.php on line 48

 

Please kindly let me know what I am missing! Thanks a lot!

Share this post


Link to post
Share on other sites
If it's properly inserting into the discount_coupons_to_orders table, you should be seeing the counts rise. Take a look in that table, if it's empty, you still have a problem on checkout_process.php.

 

My discount_coupons_to_orders table isn't completely empty, but the coupons_id column is, which would explain why the reports can't produce an accurate count.

 

It also explains the cause of that more serious error I encountered in earlier testing. The system was attempting to enter the values of '' and an orders_id number into discount_coupons_to_orders, but those values were already there.

 

Here's the code from order_process.php, which I pasted in the correct spot. It looks like the conditional code is being executed, because every time I redeem a coupon, a new entry appears in discount_coupons_to_orders, with the correct order number in the orders_id column, and no data in the coupons_id column.

 

  //kgt - discount coupons
 if( tep_session_is_registered( 'coupon' ) && is_object( $order->coupon ) ) {
   $sql_data_array = array( 'coupons_id' => $order->coupon->code,
                            'orders_id' => $insert_id );
   tep_db_perform( TABLE_DISCOUNT_COUPONS_TO_ORDERS, $sql_data_array );
 }
 //end kgt - discount coupons

 

If it helps you to see this, here are some details of my discount_coupons_to_orders table, according to PhpMyAdmin:

 

Field                Type        Null         Default
coupons_id       varchar(32)   No
orders_id          int(11)          No           0  	 


Indexes:
Keyname: PRIMARY 	
Type: PRIMARY 	
Cardinality: 4
Field: coupons_id orders_id

Share this post


Link to post
Share on other sites
  //kgt - discount coupons
 if( tep_session_is_registered( 'coupon' ) && is_object( $order->coupon ) ) {
   $sql_data_array = array( 'coupons_id' => $order->coupon->code,
                            'orders_id' => $insert_id );
   tep_db_perform( TABLE_DISCOUNT_COUPONS_TO_ORDERS, $sql_data_array );
 }
 //end kgt - discount coupons

 

 

Change this block of code to this and see if that fixes it:

 

  //kgt - discount coupons
 if( tep_session_is_registered( 'coupon' ) && is_object( $order->coupon ) ) {
  $sql_data_array = array( 'coupons_id' => $order->coupon->coupon['coupons_id'],
						 'orders_id' => $insert_id );
  tep_db_perform( TABLE_DISCOUNT_COUPONS_TO_ORDERS, $sql_data_array );
 }
 //end kgt - discount coupons


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Change this block of code to this and see if that fixes it:

 

  //kgt - discount coupons
 if( tep_session_is_registered( 'coupon' ) && is_object( $order->coupon ) ) {
  $sql_data_array = array( 'coupons_id' => $order->coupon->coupon['coupons_id'],
						 'orders_id' => $insert_id );
  tep_db_perform( TABLE_DISCOUNT_COUPONS_TO_ORDERS, $sql_data_array );
 }
 //end kgt - discount coupons

 

Yes, that worked. My most recent test resulted in the coupons_id and orders_id values properly paired in the discount_coupons_to_orders table, and the "number used" for that coupon incremented by one in the report.

 

Thank you again!

Share this post


Link to post
Share on other sites

I noticed when comparing file that \catalog\checkout_confirmation.php has anothr chnage form the earlier version at line 48 and that is not inlcuded in your instructions. The previous version had the following code segment:

 

//kgt - discount coupons

if (!tep_session_is_registered('coupon')) tep_session_register('coupon');

if (tep_not_null($HTTP_POST_VARS['coupon'])) {

//this needs to be set before the order object is created, but we must process it after

$coupon = tep_db_prepare_input($HTTP_POST_VARS['coupon']);

}

//end kgt - discount coupons

 

and the new version has:

 

//kgt - discount coupons

if (!tep_session_is_registered('coupon')) tep_session_register('coupon');

//this needs to be set before the order object is created, but we must process it after

$coupon = tep_db_prepare_input($HTTP_POST_VARS['coupon']);

//end kgt - discount coupons

 

 

Please advise about this difference. Thanks for the contributon.

Share this post


Link to post
Share on other sites

With much ease I've installed DCC 3.0 on my existing shop. Excellent feature!

I've just got one small question:

Is this list of files the only ones I have to add/modify in the other languages (NL, FR, DE)? The Admin pages I only use in English.

 

New files:

 

catalog/includes/languages/english/modules/order_total/ot_discount_coupon.php

 

Existing files:

 

admin/includes/languages/english.php

catalog/includes/languages/english.php

catalog/includes/languages/english/checkout_payment.php

 

tnks

 

gijs

Share this post


Link to post
Share on other sites
Yes, that worked. My most recent test resulted in the coupons_id and orders_id values properly paired in the discount_coupons_to_orders table, and the "number used" for that coupon incremented by one in the report.

 

Thank you again!

 

 

I've posted a bugfix for this. Thanks for bringing it to attention.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
I noticed when comparing file that \catalog\checkout_confirmation.php has anothr chnage form the earlier version at line 48 and that is not inlcuded in your instructions. The previous version had the following code segment:

 

//kgt - discount coupons

if (!tep_session_is_registered('coupon')) tep_session_register('coupon');

if (tep_not_null($HTTP_POST_VARS['coupon'])) {

//this needs to be set before the order object is created, but we must process it after

$coupon = tep_db_prepare_input($HTTP_POST_VARS['coupon']);

}

//end kgt - discount coupons

 

and the new version has:

 

//kgt - discount coupons

if (!tep_session_is_registered('coupon')) tep_session_register('coupon');

//this needs to be set before the order object is created, but we must process it after

$coupon = tep_db_prepare_input($HTTP_POST_VARS['coupon']);

//end kgt - discount coupons

Please advise about this difference. Thanks for the contributon.

 

I've changed the install instructions to reflect the change, but I don't think this needs really needs a "bugfix". It should work the same either way.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
With much ease I've installed DCC 3.0 on my existing shop. Excellent feature!

I've just got one small question:

Is this list of files the only ones I have to add/modify in the other languages (NL, FR, DE)? The Admin pages I only use in English.

 

 

If you don't need to translate the admin section, then you only have 3 files you need to worry about:

 

catalog/includes/languages/english.php

catalog/includes/languages/english/checkout_payment.php

catalog/includes/languages/english/modules/order_total/ot_discount_coupon.php


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
I'm having a problem with the discount carrying over to Paypal. When a customer has applied the discount, the updated total appears in the osC cart but the discount is gone when they get to Paypal.

 

Any suggestions?

 

 

We'd need to know more details, like what paypal module you're using, and what other contributions you have installed.

 

 

I have the same problem using the paypal ipn 2.2 and even tried your updated version the only way i can get it to work is to aggregrate it.

Share this post


Link to post
Share on other sites

Tried reinstalling this a couple of times now and always get the same errors. When clickin on Modules->Order Total I get:

 

Warning: main(/home/publicwh/public_html/includes/languages/english/modules/order_total/checkout_payment.php) [function.main]: failed to open stream: No such file or directory in /home/publicwh/public_html/admin/modules.php on line 133

 

Warning: main() [function.include]: Failed opening '/home/publicwh/public_html/includes/languages/english/modules/order_total/checkout_payment.php' for inclusion (include_path='.:/usr/lib/php') in /home/publicwh/public_html/admin/modules.php on line 133

 

Fatal error: Cannot redeclare tep_db_connect() (previously declared in /home/publicwh/public_html/admin/includes/functions/database.php:13) in /home/publicwh/public_html/admin/includes/functions/database.php on line 13

 

I've read the common errors and know I am suppose to make sure I properly modified ***File1***, but public_html/includes/languages/english/modules/order_total/checkout_payment.php does not exist in my files or in the contribution.

 

Line 133 referred to in error message is:

include(DIR_FS_CATALOG_LANGUAGES . $language . '/modules/' . $module_type . '/' . $file);

 

I am going to keep trying, but thought I would post in case someone has some tips that could save me some aggravation.

Share this post


Link to post
Share on other sites

:thumbsup: Just to say a really big thank you kgt for such a great, well documented contribution. Precisely what I have been looking for.

Share this post


Link to post
Share on other sites
If you don't need to translate the admin section, then you only have 3 files you need to worry about:

 

catalog/includes/languages/english.php

catalog/includes/languages/english/checkout_payment.php

catalog/includes/languages/english/modules/order_total/ot_discount_coupon.php

 

I've translated the text labels on the 3 pages, but in the checkout confirmation page the text "Discount Coupon 12345 applied:" stays in English?

I though this was the small portion of

catalog / includes / languages / english / modules / order_total / ot_discount_coupon.php thatw as used to create that text?

 

gijs

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

×