Jump to content



Photo
* * * * * 5 votes

[Contribution] Discount Coupon Codes


  • Please log in to reply
3394 replies to this topic

#41   realhotstuff

realhotstuff
  • Members
  • 52 posts
  • Real Name:Real Hot Stuff

Posted 11 June 2006 - 22:18

I've just installed this contribution. When I went to Admin>Catalog>Discount Coupons, I got this 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 '-20, 20' at line 1

select * from discount_coupons cd order by cd.date_end, date_start limit -20, 20


I looked into the code in coupons.php and could not find the 'limit -20, 20'.


Anyone can help me with this?

#42   enigma1

enigma1
  • Members
  • 8,206 posts
  • Real Name:Mark Samios

Posted 11 June 2006 - 23:23

I've just installed this contribution. When I went to Admin>Catalog>Discount Coupons, I got this 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 '-20, 20' at line 1

select * from discount_coupons cd order by cd.date_end, date_start limit -20, 20
I looked into the code in coupons.php and could not find the 'limit -20, 20'.
Anyone can help me with this?


This is not contribution related but rather a problem with the older version of osc. See this page, fix at the end:
http://www.oscommerc...unity/bugs,1605

ideally you should download the latest osc update and upgrade your store that includes this fix.
http://www.oscommerc...tions/downloads

#43   realhotstuff

realhotstuff
  • Members
  • 52 posts
  • Real Name:Real Hot Stuff

Posted 12 June 2006 - 00:09

This is not contribution related but rather a problem with the older version of osc. See this page, fix at the end:
http://www.oscommerc...unity/bugs,1605

ideally you should download the latest osc update and upgrade your store that includes this fix.
http://www.oscommerc...tions/downloads


That solved the problem. Thanks a lot. I already made too many changes to the code and it will be hard for me to aplly all the patches.

Thanks.

#44   DarrenWu

DarrenWu
  • Members
  • 23 posts
  • Real Name:Darren

Posted 12 June 2006 - 02:06

Did you download the latest? There was a bugfix for that problem.


Kgt, I download and installed your newest update package ot_discount_coupon_codes_1.2_1, I have the same problem, looks like the "Max Use" doesn't work.

Hopefully, you can double check the codes.

Thank you very much for this nice addon!!!

#45   DarrenWu

DarrenWu
  • Members
  • 23 posts
  • Real Name:Darren

Posted 12 June 2006 - 02:36

Kgt, I have a suggestion about the codes for Max Use in your addon.

The codes you wrote for Max Use is:
if( $row['max_use'] != '0' ) { //if max_use==0, then use is unlimited, otherwise, we need to verify the customer hasn't used this coupon more than max_use times
					$check_use_query = tep_db_query($sql = "select count(*) as cnt from ".TABLE_ORDERS." o inner join ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." dc2o on dc2o.orders_id=o.orders_id and o.customers_id = 2 and dc2o.coupons_id='".tep_db_prepare_input( $HTTP_POST_VARS['coupon'] )."'");
					$use = tep_db_fetch_array( $check_use_query );
					if( $row['max_use'] > $use['cnt'] ) $passed = true; //proceed if max_use is greater than the number of times this customer has used the code 
					else {
						$error_message[] = sprintf( ENTRY_DISCOUNT_COUPON_USE_ERROR, $use['cnt'], $row['max_use'] ); //display the error message for number of times used
					}

I don know why it doesn't work at all, but looks like if we try to get the value of how many times the coupon had been used, the program need to go throw orders and discount_coupons_to_orders 2 tables.

If there are a lot of orders in those 2 tables, it will take longer time to match those orders.

I think the better way to count how many times the coupon already been used is to create a new table call "coupons_used_times" (with coupon and times )only for counting the times. so $row['max_use'] just need to match the value from the "coupons_used_times".

Sorry about my poor English and knowledge on PHP. Just for an idea

#46   kgt

kgt
  • Members
  • 2,883 posts
  • Real Name:KG Thorson

Posted 12 June 2006 - 16:59

Kgt, I have a suggestion about the codes for Max Use in your addon.

I don know why it doesn't work at all, but looks like if we try to get the value of how many times the coupon had been used, the program need to go throw orders and discount_coupons_to_orders 2 tables.

If there are a lot of orders in those 2 tables, it will take longer time to match those orders.

I think the better way to count how many times the coupon already been used is to create a new table call "coupons_used_times" (with coupon and times )only for counting the times. so $row['max_use'] just need to match the value from the "coupons_used_times".

Sorry about my poor English and knowledge on PHP. Just for an idea



Darren, you are correct that the join will slow things down if both tables are large. You have brought to my attention that an index should be placed on the orders table for the customers_id and an index on the discount_coupons_to_orders table for the orders_id.

Remember that the max_use limits the usage per customer. This means we must have some way to join the coupon code usage to a customer. We can create a table called customer count with a coupon id and a customer_id and an order count, but this removes another possibility that others have requested: a way to see which coupons were used on which orders. DCC is an order_total module, which means it goes in the orders_total table as a text line with an amount. A report would require searching the field for the text value, which would be slower than a join on integer values. It seems to me a toss-up which would be better. The code only does a join if 1) the customer uses a coupon code and 2) the code has a max_use that's no unlimited.

#47   kgt

kgt
  • Members
  • 2,883 posts
  • Real Name:KG Thorson

Posted 12 June 2006 - 17:04

Kgt, I download and installed your newest update package ot_discount_coupon_codes_1.2_1, I have the same problem, looks like the "Max Use" doesn't work.


Darren, didn't even notice this until I saw the code you posted. It doesn't work because the customer id got hard-coded!

Line 82 of checkout_confirmation.php replace:

$check_use_query = tep_db_query($sql = "select count(*) as cnt from ".TABLE_ORDERS." o inner join ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." dc2o on dc2o.orders_id=o.orders_id and o.customers_id = 2 and dc2o.coupons_id='".tep_db_prepare_input( $HTTP_POST_VARS['coupon'] )."'");
with
$check_use_query = tep_db_query($sql = "select count(*) as cnt from ".TABLE_ORDERS." o inner join ".TABLE_DISCOUNT_COUPONS_TO_ORDERS." dc2o on dc2o.orders_id=o.orders_id and o.customers_id = '".$customer_id."' and dc2o.coupons_id='".tep_db_prepare_input( $HTTP_POST_VARS['coupon'] )."'");


#48   kgt

kgt
  • Members
  • 2,883 posts
  • Real Name:KG Thorson

Posted 12 June 2006 - 19:52

In Admin -> coupons.php, when I create a new Discount Coupon, the date shows is in MM/DD/YYYY.

How do I change to DD/MM/YYYY? My entire site is DD/MM/YYY. If i can mod this discount code contribution to be DD/MM/YYYY, that would be perfect.


For those that wish to use other date formats, you may download the latest which should work. You will need to enter dates in the same format you display them - ie, if you display dates as dd/mm/yyyy, you need to enter them the same way, not as dd/mm/yy, for example. This is set by DATE_FORMAT_SHORT and DATE_FORMAT in includes/languages/english.php (or your corresponding language file).

#49   kgt

kgt
  • Members
  • 2,883 posts
  • Real Name:KG Thorson

Posted 12 June 2006 - 20:07

Hi! I'm so happy to see this contribution - I've been working on something similar, but kept getting sidetracked. One odd bit of behaviour I'm noticing, though...

I've put the first coupon in and everything seems to work fine. However, if I put in an invalid code, it returns to the payment page, shows the error message as part of the URL, but does not actually display it anywhere on the screen. Any ideas? Thank you!


Do you have a modified header.php that does not contain some version of this code?

<?php
  if (isset($HTTP_GET_VARS['error_message']) && tep_not_null($HTTP_GET_VARS['error_message'])) {
?>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
  <tr class="headerError">
	<td class="headerError"><?php echo htmlspecialchars(urldecode($HTTP_GET_VARS['error_message'])); ?></td>
  </tr>
</table>
<?php
  }

  if (isset($HTTP_GET_VARS['info_message']) && tep_not_null($HTTP_GET_VARS['info_message'])) {
?>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
  <tr class="headerInfo">
	<td class="headerInfo"><?php echo htmlspecialchars($HTTP_GET_VARS['info_message']); ?></td>
  </tr>
</table>
<?php
  }
?>

If you have a template and have completely redone your includes/header.php, you might be missing this code. This contribution assumes the standard error message code works.

#50   kgt

kgt
  • Members
  • 2,883 posts
  • Real Name:KG Thorson

Posted 12 June 2006 - 20:38

I have installed the Coupons add-on which I really love only there is a small problem; everything works fine until the shopping cart is being passed through to PayPal. There I see the price without the discount.



You're not going to see the order total line for the discount coupon in Paypal. Paypal displays the subtotal, the shipping, and the total. You should make sure you have "Display Subtotal with Applied Discount" set to true in Modules > Order Total > Discount Coupons. Verify that your subtotal displayed by Paypal is the item total - discount + taxes, and the total is the subtotal + shipping.

#51   WingingIt

WingingIt
  • Members
  • 33 posts
  • Real Name:Kristen Randle

Posted 12 June 2006 - 21:54

I'm trying to install the script, but there's one problem. There are files which you tell me to put in the admin folder. but I don't have an admin folder on the main level. My admin folder is inside the catalog folder. What should I do?

#52   WingingIt

WingingIt
  • Members
  • 33 posts
  • Real Name:Kristen Randle

Posted 12 June 2006 - 22:59

Okay - my truely, honestly brilliant son walked me through the entire installation process. But when we tried to run the script, going to the admin, selecting catalogue, and then discount coupons, we got the following error message: The requested URL /Bookshop/nfoscomm/catalog/admin/FILENAME_DISCOUNT_COUPONS was not found on this server.

Then, when we tried to access the store, the whole index page had blown up - the index page is all code. The images and the graphics are at the very bottom of the page, after the huge body of code with the following code written in the middle of it all:

Warning: main(includes/modules/FILENAME_UPCOMING_PRODUCTS): failed to open stream: No such file or directory in /mnt/w0514/d13/s29/b026d285/www/Bookshop/nfoscomm/catalog/index.php on line 316

Warning: main(): Failed opening 'includes/modules/FILENAME_UPCOMING_PRODUCTS' for inclusion (include_path='.:/usr/local/nf/lib/php') in /mnt/w0514/d13/s29/b026d285/www/Bookshop/nfoscomm/catalog/index.php on line 316
TEXT_GREETING_GUEST

We are so excited to be able to provide you with this newly printed version of The Only Alien on the Planet. English teachers representing schools: please post us for special educational pricing. We'd love to help you with classroom sets. We can ship to you by the very slow but cost-effective media mail, or we can shoot something off to you over-night. Choose your shipping method, check out, and we're off.


Warning: main(includes/modules/FILENAME_NEW_PRODUCTS): failed to open stream: No such file or directory in /mnt/w0514/d13/s29/b026d285/www/Bookshop/nfoscomm/catalog/index.php on line 313

Warning: main(): Failed opening 'includes/modules/FILENAME_NEW_PRODUCTS' for inclusion (include_path='.:/usr/local/nf/lib/php') in /mnt/w0514/d13/s29/b026d285/www/Bookshop/nfoscomm/catalog/index.php on line 313


]All we did was install the files as instructed - one at a time. I noticed, when I started setting up this store, that the instructions I got from NetFirms for inserting my logo and replacing text on the index page referenced files that were not present in the actual program files - or that had different names. I made assumptions as to what was what, and I did okay - everything worked and what I changed stayed changed. But this is overwhelming.

Does anybody have a clue what we did wrong?

#53   kgt

kgt
  • Members
  • 2,883 posts
  • Real Name:KG Thorson

Posted 12 June 2006 - 23:46

Okay - my truely, honestly brilliant son walked me through the entire installation process. But when we tried to run the script, going to the admin, selecting catalogue, and then discount coupons, we got the following error message: The requested URL /Bookshop/nfoscomm/catalog/admin/FILENAME_DISCOUNT_COUPONS was not found on this server.

Then, when we tried to access the store, the whole index page had blown up - the index page is all code. The images and the graphics are at the very bottom of the page, after the huge body of code with the following code written in the middle of it all:

Warning: main(includes/modules/FILENAME_UPCOMING_PRODUCTS): failed to open stream: No such file or directory in /mnt/w0514/d13/s29/b026d285/www/Bookshop/nfoscomm/catalog/index.php on line 316

Warning: main(): Failed opening 'includes/modules/FILENAME_UPCOMING_PRODUCTS' for inclusion (include_path='.:/usr/local/nf/lib/php') in /mnt/w0514/d13/s29/b026d285/www/Bookshop/nfoscomm/catalog/index.php on line 316
TEXT_GREETING_GUEST

We are so excited to be able to provide you with this newly printed version of The Only Alien on the Planet. English teachers representing schools: please post us for special educational pricing. We'd love to help you with classroom sets. We can ship to you by the very slow but cost-effective media mail, or we can shoot something off to you over-night. Choose your shipping method, check out, and we're off.
Warning: main(includes/modules/FILENAME_NEW_PRODUCTS): failed to open stream: No such file or directory in /mnt/w0514/d13/s29/b026d285/www/Bookshop/nfoscomm/catalog/index.php on line 313

Warning: main(): Failed opening 'includes/modules/FILENAME_NEW_PRODUCTS' for inclusion (include_path='.:/usr/local/nf/lib/php') in /mnt/w0514/d13/s29/b026d285/www/Bookshop/nfoscomm/catalog/index.php on line 313


]All we did was install the files as instructed - one at a time. I noticed, when I started setting up this store, that the instructions I got from NetFirms for inserting my logo and replacing text on the index page referenced files that were not present in the actual program files - or that had different names. I made assumptions as to what was what, and I did okay - everything worked and what I changed stayed changed. But this is overwhelming.

Does anybody have a clue what we did wrong?


You have either lost a bunch of entries in includes/filenames.php, or you have removed that file, or something else. The first step is to check that those entries exist in includes/filenames.php.

#54   kgt

kgt
  • Members
  • 2,883 posts
  • Real Name:KG Thorson

Posted 12 June 2006 - 23:47

I'm trying to install the script, but there's one problem. There are files which you tell me to put in the admin folder. but I don't have an admin folder on the main level. My admin folder is inside the catalog folder. What should I do?


The admin folder can be anywhere. If it's inside your catalog folder, then that's where it is.

#55   WingingIt

WingingIt
  • Members
  • 33 posts
  • Real Name:Kristen Randle

Posted 13 June 2006 - 00:01

The admin folder can be anywhere. If it's inside your catalog folder, then that's where it is.



Okay. Well, we put the files in the admin folder, figuring that was where they were supposed to go. It's just that the admin folder in our version of the program was not at the location mapped out in the instructions. Remember, I (not the son, the store owner) am admittedly stupid. And here comes yet another stupid question - an admin file is propriatory? Meaning there will only be one in a given program?

#56   maz

maz
  • Members
  • 161 posts
  • Real Name:mazhar

Posted 13 June 2006 - 00:08

I am a bit confused. Someone on the forum suggested that I need to install the Credit Class & Gift Voucher contribution first. Is that correct? Ireally dont need that one..

I only need coupons and this 'Discount Coupon Codes' would be great if it works on its own.

Please advise..
Thanks

#57   WingingIt

WingingIt
  • Members
  • 33 posts
  • Real Name:Kristen Randle

Posted 13 June 2006 - 01:55

You have either lost a bunch of entries in includes/filenames.php, or you have removed that file, or something else. The first step is to check that those entries exist in includes/filenames.php.


They aren't in includes/filenames.php. In Cat/Inc/modules I have /upcoming_products but without the FILENAMES_ in front of it. This is true with the other names as well.

I have re-copied the contributions file filenames.php into into admin/includes. it still does not contain those names.

I have been through every one of the contributions files, checked them all—all are installed.

The problem seems to be in a directory in the index.php, lines 316, 313? I have lost a directory somehow?

The rest of you guys seem to know so much. You don't get lost like this.

#58   kgt

kgt
  • Members
  • 2,883 posts
  • Real Name:KG Thorson

Posted 13 June 2006 - 02:47

I am a bit confused. Someone on the forum suggested that I need to install the Credit Class & Gift Voucher contribution first. Is that correct? Ireally dont need that one..

I only need coupons and this 'Discount Coupon Codes' would be great if it works on its own.


This is in no way connected to CCGV and does not rely on it.

#59   kgt

kgt
  • Members
  • 2,883 posts
  • Real Name:KG Thorson

Posted 13 June 2006 - 02:53

They aren't in includes/filenames.php. In Cat/Inc/modules I have /upcoming_products but without the FILENAMES_ in front of it. This is true with the other names as well.

I have re-copied the contributions file filenames.php into into admin/includes. it still does not contain those names.

I have been through every one of the contributions files, checked them all—all are installed.

The problem seems to be in a directory in the index.php, lines 316, 313? I have lost a directory somehow?


Is there an entry in includes/filenames.php that says:
define( 'FILENAME_UPCOMING_PRODUCTS', 'upcoming_products.php' );


The rest of you guys seem to know so much. You don't get lost like this.

We did at one point. Hang in there.

#60   kgt

kgt
  • Members
  • 2,883 posts
  • Real Name:KG Thorson

Posted 13 June 2006 - 02:59

Okay. Well, we put the files in the admin folder, figuring that was where they were supposed to go. It's just that the admin folder in our version of the program was not at the location mapped out in the instructions. Remember, I (not the son, the store owner) am admittedly stupid. And here comes yet another stupid question - an admin file is propriatory? Meaning there will only be one in a given program?


Don't know quite what you mean by only one in a given program. There can be (and should be) several files of the same name, but they do not exist in the same directory. For example, the language files (in includes/languages) have the same name as the code files they provide the text for.

The admin section is a different ball game. It may be in your catalog directory, but it does not have to be. Some people put it in a different place, or name it a different name. That is why the instructions treat it like it's on the same level as the catalog. When you install to the catalog and to the admin, you're almost doing two different installations. There's technically no reason you must install the admin part (you could install the module manually in the database and create coupons directly and they'd still work no problem.)