Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Discount Coupon Codes


kgt

Recommended Posts

So I tried searching to find if anyone found a way to do Inclusions instead of Exclusions. After not finding anything I dug into the code myself and found a pretty simple and fast solution for the category, product, manufacturer, customer and shipping zone exclusion/inclusion options.

 

In catalog\includes\classes\discount_coupon.php

 

To change categories, products and manufacturers

 

on lines 225 (category check), 247 (product check), 274 (manufacturer check) change:

         return false;

 

to:

         return true;

 

And on line 290 change:

     return true;

 

to:

     return false;

 

 

To change customers

 

On line 66 change:

       if( tep_db_num_rows( $check_user_query ) > 0 ) {

 

To:

       if( tep_db_num_rows( $check_user_query ) == 0 ) {

 

 

To change shipping zone

 

On line 80 change:

       if( tep_db_num_rows( $check_user_query ) > 0 ) {

 

To:

       if( tep_db_num_rows( $check_user_query ) == 0 ) {

 

 

:thumbsup:

Link to comment
Share on other sites

Hi all,

I have seen posts with this problem, but no one has offered a solution.

 

I have installed version 3.34, all seems to go smoothly. If I enter the testing001 code the discount applies correctly etc.

 

However, in Admin, if i go to my admin/coupon.php page, to add/edit coupons, the page is blank after the link to the instructions. If I view the html source in the browser, it ends at:

Click here to read the Discount Coupon Codes manual for help editing coupons.</a></td>
         </tr>
       </table></td>
     </tr>

 

I tried removing the code that builds the Coupon table down to the closing <!-- body_text_eof //--> and page displayed correctly, so I can only assume there is a simple HTML tag missing, malformed or broken due to another contrib somewhere in the file.

 

Any ideas, anyone?

 

thanks

Link to comment
Share on other sites

Hi all,

I have seen posts with this problem, but no one has offered a solution.

 

I have installed version 3.34, all seems to go smoothly. If I enter the testing001 code the discount applies correctly etc.

 

However, in Admin, if i go to my admin/coupon.php page, to add/edit coupons, the page is blank after the link to the instructions. If I view the html source in the browser, it ends at:

Click here to read the Discount Coupon Codes manual for help editing coupons.</a></td>
         </tr>
       </table></td>
     </tr>

 

I tried removing the code that builds the Coupon table down to the closing <!-- body_text_eof //--> and page displayed correctly, so I can only assume there is a simple HTML tag missing, malformed or broken due to another contrib somewhere in the file.

 

Any ideas, anyone?

 

thanks

 

 

I managed to fix this conflict. it turned out to be in the currencies class declaration. i found in line 183:

require(DIR_WS_CLASSES . 'currencies.php');

$currencies = new currencies();

 

if i changed to require_once it now works correctly.

require_once(DIR_WS_CLASSES . 'currencies.php');

$currencies = new currencies();

 

 

worked for me, worth a try for anyone else, good luck...

 

r

Link to comment
Share on other sites

Does the error message show up after they are redirected to login?

 

Can you post the code on your checkout_payment.php page - everything above the </head><body> tags?

 

Hi Tracys, this bug happens every time when the end user enters the wrong coupon code. Does not make any difference if they have already logged in or not. The site url is www.365lingerie.com - feel free to place a dummy order and enter a random coupon code and you will see the bug ... you will be asked to login again even though if you already have logged in ...

 

 

Here is the code:

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

 

<?php

/*

$Id: checkout_payment.php,v 1.113 2003/06/29 23:03:27 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

require('includes/application_top.php');

 

// if the customer is not logged on, redirect them to the login page

if (!tep_session_is_registered('customer_id')) {

$navigation->set_snapshot();

tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));

}

 

// if there is nothing in the customers cart, redirect them to the shopping cart page

if ($cart->count_contents() < 1) {

tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));

}

 

// if no shipping method has been selected, redirect the customer to the shipping method selection page

if (!tep_session_is_registered('shipping')) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

}

 

// avoid hack attempts during the checkout procedure by checking the internal cartID

if (isset($cart->cartID) && tep_session_is_registered('cartID')) {

if ($cart->cartID != $cartID) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

}

}

 

// Stock Check

if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {

$products = $cart->get_products();

for ($i=0, $n=sizeof($products); $i<$n; $i++) {

if (tep_check_stock($products[$i]['id'], $products[$i]['quantity'])) {

tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));

break;

}

}

}

 

// if no billing destination address was selected, use the customers own address as default

if (!tep_session_is_registered('billto')) {

tep_session_register('billto');

$billto = $customer_default_address_id;

} else {

// verify the selected billing address

$check_address_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$billto . "'");

$check_address = tep_db_fetch_array($check_address_query);

 

if ($check_address['total'] != '1') {

$billto = $customer_default_address_id;

if (tep_session_is_registered('payment')) tep_session_unregister('payment');

}

}

 

require(DIR_WS_CLASSES . 'order.php');

$order = new order;

 

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

 

$total_weight = $cart->show_weight();

$total_count = $cart->count_contents();

 

// load all enabled payment modules

require(DIR_WS_CLASSES . 'payment.php');

$payment_modules = new payment;

 

require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_PAYMENT);

 

$breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

$breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));

?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html <?php echo HTML_PARAMS; ?>>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<?php

# cDynamic Meta Tags

/*<title><?php echo TITLE; ?>*/

require(DIR_WS_INCLUDES . 'meta_tags.php');

#

?>

<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">

<link rel="stylesheet" type="text/css" href="stylesheet.css"><LINK REL="SHORTCUT ICON" HREF="/favicon.ico">

<script language="javascript"><!--

var selected;

 

function selectRowEffect(object, buttonSelect) {

if (!selected) {

if (document.getElementById) {

selected = document.getElementById('defaultSelected');

} else {

selected = document.all['defaultSelected'];

}

}

 

if (selected) selected.className = 'moduleRow';

object.className = 'moduleRowSelected';

selected = object;

 

// one button is not an array

if (document.checkout_payment.payment[0]) {

document.checkout_payment.payment[buttonSelect].checked=true;

} else {

document.checkout_payment.payment.checked=true;

}

}

 

function rowOverEffect(object) {

if (object.className == 'moduleRow') object.className = 'moduleRowOver';

}

 

function rowOutEffect(object) {

if (object.className == 'moduleRowOver') object.className = 'moduleRow';

}

 

function popupWindow(url) {

window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=500,screenX=150,screenY=30,top=30,left=150')

}

//--></script>

<?php echo $payment_modules->javascript_validation(); ?>

</head>

Link to comment
Share on other sites

In case anyone is curious about the solution to my problem regarding Fatal Error for unregistered global variable 'coupon' on the checkout_confirmation.php page while using the Register Global off add-on, you have to add:

 

'coupon' => true,

 

to the $var_refs array in the 'link_session_variable' function in \catalog\includes\functions\sessions.php file for this error to go away.

Link to comment
Share on other sites

Hi!

I installed the discount coupon module V3.34 with osCommerce V2.2 today and installation worked fine, but now I have problems to use a coupon in a test order.

The discount is not discounted, but added to order total.

 

Do you have an idea how I can solve this problem? Or is this bug already known?

 

 

Thanks,

Ulrike

Link to comment
Share on other sites

Hi!

I installed the discount coupon module V3.34 with osCommerce V2.2 today and installation worked fine, but now I have problems to use a coupon in a test order.

The discount is not discounted, but added to order total.

 

Do you have an idea how I can solve this problem? Or is this bug already known?

 

 

Thanks,

Ulrike

 

I found the reason for miscalculation. I don't use taxes, whatever, when I set tax rate to 0% calculation is correct.

Link to comment
Share on other sites

What I do know, is it has something to do with the way the session id is being handled. What I don't know is which page to troubleshoot. My first thought is checkout_confirmation.php What do you have on that page above this bit of code:

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>

 

Hi Tracys, this bug happens every time when the end user enters the wrong coupon code. Does not make any difference if they have already logged in or not. The site url is www.365lingerie.com - feel free to place a dummy order and enter a random coupon code and you will see the bug ... you will be asked to login again even though if you already have logged in ...

 

 

Here is the code:

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

 

<?php

/*

$Id: checkout_payment.php,v 1.113 2003/06/29 23:03:27 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

require('includes/application_top.php');

 

// if the customer is not logged on, redirect them to the login page

if (!tep_session_is_registered('customer_id')) {

$navigation->set_snapshot();

tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));

}

 

// if there is nothing in the customers cart, redirect them to the shopping cart page

if ($cart->count_contents() < 1) {

tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));

}

 

// if no shipping method has been selected, redirect the customer to the shipping method selection page

if (!tep_session_is_registered('shipping')) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

}

 

// avoid hack attempts during the checkout procedure by checking the internal cartID

if (isset($cart->cartID) && tep_session_is_registered('cartID')) {

if ($cart->cartID != $cartID) {

tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

}

}

 

// Stock Check

if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {

$products = $cart->get_products();

for ($i=0, $n=sizeof($products); $i<$n; $i++) {

if (tep_check_stock($products[$i]['id'], $products[$i]['quantity'])) {

tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));

break;

}

}

}

 

// if no billing destination address was selected, use the customers own address as default

if (!tep_session_is_registered('billto')) {

tep_session_register('billto');

$billto = $customer_default_address_id;

} else {

// verify the selected billing address

$check_address_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$billto . "'");

$check_address = tep_db_fetch_array($check_address_query);

 

if ($check_address['total'] != '1') {

$billto = $customer_default_address_id;

if (tep_session_is_registered('payment')) tep_session_unregister('payment');

}

}

 

require(DIR_WS_CLASSES . 'order.php');

$order = new order;

 

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

 

$total_weight = $cart->show_weight();

$total_count = $cart->count_contents();

 

// load all enabled payment modules

require(DIR_WS_CLASSES . 'payment.php');

$payment_modules = new payment;

 

require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_PAYMENT);

 

$breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));

$breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));

?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html <?php echo HTML_PARAMS; ?>>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<?php

# cDynamic Meta Tags

/*<title><?php echo TITLE; ?>*/

require(DIR_WS_INCLUDES . 'meta_tags.php');

#

?>

<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">

<link rel="stylesheet" type="text/css" href="stylesheet.css"><LINK REL="SHORTCUT ICON" HREF="/favicon.ico">

<script language="javascript"><!--

var selected;

 

function selectRowEffect(object, buttonSelect) {

if (!selected) {

if (document.getElementById) {

selected = document.getElementById('defaultSelected');

} else {

selected = document.all['defaultSelected'];

}

}

 

if (selected) selected.className = 'moduleRow';

object.className = 'moduleRowSelected';

selected = object;

 

// one button is not an array

if (document.checkout_payment.payment[0]) {

document.checkout_payment.payment[buttonSelect].checked=true;

} else {

document.checkout_payment.payment.checked=true;

}

}

 

function rowOverEffect(object) {

if (object.className == 'moduleRow') object.className = 'moduleRowOver';

}

 

function rowOutEffect(object) {

if (object.className == 'moduleRowOver') object.className = 'moduleRow';

}

 

function popupWindow(url) {

window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=500,screenX=150,screenY=30,top=30,left=150')

}

//--></script>

<?php echo $payment_modules->javascript_validation(); ?>

</head>

~Tracy
 

Link to comment
Share on other sites

I added this contribution, added the sql in to the database

 

I see it in the admin>customers>coupons

 

then I go to the modules > order total and nothing is there.

 

I went to the online store and entered the code, didn't give me an error but it didn't apply it.

 

I went back and added the php files again just to make sure I didn't mess up and it is still doing it.

Link to comment
Share on other sites

Have you tried comparing the files you changed to the files in the contribution with a program like WinMerge? Sometimes it can just be a simple mis-placement of a bit of code above or below where it needs to be ;)

 

I added this contribution, added the sql in to the database

 

I see it in the admin>customers>coupons

 

then I go to the modules > order total and nothing is there.

 

I went to the online store and entered the code, didn't give me an error but it didn't apply it.

 

I went back and added the php files again just to make sure I didn't mess up and it is still doing it.

~Tracy
 

Link to comment
Share on other sites

I have just added this contribution to my MS2 RC2 and noticed that Taxes are no longer calculated on Shipping costs. Previously to adding this contribution, Taxes

were calculated on the Shipping charge. Does anyone know where to look to find out why?

 

BTW - I also have the Loyalty Discount contribution installed, and it worked fine prior to adding this Discount Coupon contribution in regards to calculating the tax.

 

My order looks like this:

SubTotal

Loyalty Discount (if any)

Discount Coupon

Shipping

Tax

Total

 

Tax should be calculated on Subtotal - Loyalty Discount - Discount Coupon + Shipping.

Instead I get

Tax calculated on just Subtotal - Loyalty Discount - Discount Coupon.

 

Any help would be appreciated.

 

Doc

Link to comment
Share on other sites

Is the sort order setup to reflect this in Admin->Modules->Order Total->Discount Coupon

 

I have just added this contribution to my MS2 RC2 and noticed that Taxes are no longer calculated on Shipping costs. Previously to adding this contribution, Taxes

were calculated on the Shipping charge. Does anyone know where to look to find out why?

 

BTW - I also have the Loyalty Discount contribution installed, and it worked fine prior to adding this Discount Coupon contribution in regards to calculating the tax.

 

My order looks like this:

SubTotal

Loyalty Discount (if any)

Discount Coupon

Shipping

Tax

Total

 

Tax should be calculated on Subtotal - Loyalty Discount - Discount Coupon + Shipping.

Instead I get

Tax calculated on just Subtotal - Loyalty Discount - Discount Coupon.

 

Any help would be appreciated.

 

Doc

~Tracy
 

Link to comment
Share on other sites

Yes, and thanks for the reply. But it looks like I got it fixed. Apparently the USPS shipping module was not working correctly, so once I

unloaded that and then re-installed USPS module, the tax calculation worked as it should. Just took me awhile to work thru the issues.

 

Thanks. This is going to be a valuable contribution.

 

Now I can get on with the testing........

 

Doc

Link to comment
Share on other sites

This is the support thread for the Order Total contribution Discount Coupon Codes found here:

 

http://www.oscommerce.com/community/contributions,4269

 

If I want to use this add-on, how do I know what changes mentioned in this support thread need to be applied? It does not appear the add-on download has been updated in some months. Meanwhile innumerable posts change this line that line etc.

What I need is an add-on that tracks pre-set spending amounts for employee accounts. So for instance someone has $100 on account they can spend until it's used up then after that they fork over their own money. I'm trying to find the thread for a gift certificate as I think that may be the only way to make that work.

Link to comment
Share on other sites

I'm thinking gift certificate may be the way to go on that one. They can use a code for a discount, but it isn't going to keep track of how much of that discount they used.

 

Do a search in the contributions for Gift Certificate and see what contributions come up - there may be some new one's since I last looked ;)

 

If I want to use this add-on, how do I know what changes mentioned in this support thread need to be applied? It does not appear the add-on download has been updated in some months. Meanwhile innumerable posts change this line that line etc.

What I need is an add-on that tracks pre-set spending amounts for employee accounts. So for instance someone has $100 on account they can spend until it's used up then after that they fork over their own money. I'm trying to find the thread for a gift certificate as I think that may be the only way to make that work.

~Tracy
 

Link to comment
Share on other sites

I hate to post another question, but now I am stuck. Like a few other posts I have found, my discount is not passed to Paypal IPN. I

am using the PayPal IPN v2.3.4 (although it says v2.3.3) contribution, and have made sure that the Transaction type is set to 'aggregate'.

I believe I had to do that back when I installed the Loyalty Discount v 1.51. With the Loyalty Discount, the correct subtotal is showed

when passed to PayPal IPN.

 

I have also made the modification to the paypal_ipn.php file as specified in the contribution.

 

The Order Confirmation screen looks good on first entry after entering in a test coupon code and selecting Paypal as payment. All numbers look correct. However,

if I refresh this Order Confirmation screen, I get the following error on top of the screen:

 

1062 - Duplicate entry '10%Thanks-80' for key 1

 

insert into discount_coupons_to_orders (coupons_id, orders_id) values ('10%Thanks', '80')

 

[TEP STOP]

 

The 10%Thanks is my coupon code I am testing with.

 

Any ideas where I look as to why the error and why this discount is not passed to PayPal?

Link to comment
Share on other sites

Ok, I finally got the correct total passed to Paypal, but it is ugly. Since I am also using the Loyalty Discount contrib, I had to do the following:

1. Make sure the Coupon Discount is first and the Loyalty Discount is second.

2. Make sure you check that the Subtotal reflects the Coupon Discount discount.

 

So right now I can live with that. But there is still the problem of reloading the Order Confirmation screen or backing up one screen to the

payment Information screen, changing nothing, then hitting Continue. If using the Paypal IPN, then I get the 1062 Duplicate Entry error.

 

I only accept two forms of payment - Check or Paypal. If I select Check and enter a coupon code, then I can bounce between the Payment Information

Screen and Order Confirmation all day long and the totals are correct, and no 1062 error. But if I select paypal first on the Payment Screen,

then go to the Order Confirmation screen, hit back to go back to payment screen, change nothing, then select Continue, then sometims I'll get the 1062 error

and the discount, and sometimes I'll not get the error but no discount. Real flakey!!!! BTW I am using Mozilla Firefox and have not tested with other browsers.

 

 

 

Can anyone tell me if there is a 'newer' 'better supported' Discount Coupon contrib available that works?

Link to comment
Share on other sites

I think the error is on the checkout_process.php

I have blank page when I finish the checkout_confirmation.php

 

I have modified the osc with tree theme and Simple Multiple Images (Unlimited) with PrettyPhoto Popups V0.9

 

do I need to paste the checkout_process.php script!?

Link to comment
Share on other sites

Hi everyone,

I have installed Discount coupon codes 3.34 in my OSC v2.2 rc2.

The modules calcules good but there is a BUG:

It creates ONE entry for EVERY pay modules.

Due i have 2 payment modules (paypal ipn and COD) it creates 2 entries (??)

Also, the first entry do not apply the discount!.

Any ideas to solve this BUG will be very appreciated.

many thanks and congrats for the forum

best regards

Jordi

Link to comment
Share on other sites

discount coupons for the products described in module module together how to exclusion

eg, such as specials

//specials exclusion

if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_EXCLUDE_SPECIALS == 'true' ) {

if( ( $special_price = tep_get_products_special_price( $product_id ) ) !== null ) {

$this->cart_info['exclusions']['products'][] = $product_id;

if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG == 'true' ) $this->message( 'INFO: Product '.$product_id.' failed specials exclusion check. Adding product to excluded products array.', 'debug' );

return false;

}

}

Link to comment
Share on other sites

- Discount coupon does not display in order subtotal during checkout confirmation.

Ensure the discount coupon has a unique sort order. Set this in Modules > Order Total. Also double check that you have added the changes to includes/classes/order.php and checkout_confirmation.php as outlined above.

 

 

Hi everyone,

 

I'm having this problem that was mentioned in the troubleshooting section. I've installed Dynamo PayPal WPP which works fine, but I can't seem to get any coupon form to show up in checkout even though it works perfectly in the admin. I've triple checked the installation procedure and installed it in admin-modules, and the only thing that's off is that the section overwritten on line 244 of order.php is slightly different in osC rc2a than what's in the instruction files which were written for MS1. Any ideas as to what I'm missing?

 

Thanks

Link to comment
Share on other sites

- Discount coupon does not display in order subtotal during checkout confirmation.

Ensure the discount coupon has a unique sort order. Set this in Modules > Order Total. Also double check that you have added the changes to includes/classes/order.php and checkout_confirmation.php as outlined above.

 

 

Hi everyone,

 

I'm having this problem that was mentioned in the troubleshooting section. I've installed Dynamo PayPal WPP which works fine, but I can't seem to get any coupon form to show up in checkout even though it works perfectly in the admin. I've triple checked the installation procedure and installed it in admin-modules, and the only thing that's off is that the section overwritten on line 244 of order.php is slightly different in osC rc2a than what's in the instruction files which were written for MS1. Any ideas as to what I'm missing?

 

Thanks

 

 

     <?php
/* kgt - discount coupons */
//	if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_STATUS == 'true' )
 {
?>
     <tr>

 

Ok I guess I found the section of code where I had a problem. In checkout_payment.php, line 381, I just commented out the 'If' clause, making it so that Discount Coupons will always be enabled, which is what I want anyways. Are there any side effects to this that anyone might know of? Might it screw up a payment module?

 

Thanks again,

 

Nick

Link to comment
Share on other sites

I installed v3.34 of this module.

 

It works fine except for orders placed using Paypal IPN or Nochex APC and probably other payment methods that bypass checkout_process.php

 

It seems the session was not created when a user chose these payment methods because after confirmation, they are whisked off to the payment provider's site, and therefore the coupon was not marked as used for that user even though the order and amounts/discounts went through fine.

 

This meant the user could re-use the same coupon code at a later date.

 

As Paypal IPN is used quite a lot, I thought I would post my hack/fix here

 

open catalog/ext/modules/payment/paypal_ipn/ipn.php

find:

       if ($_POST['payment_status'] == 'Pending') {
         $comment_status .= '; ' . $_POST['pending_reason'];

Add after:

	  // UKSB Apply discount coupon
		//Check to see if the discount coupon has already been applied to the order
		$discount_to_order_query = tep_db_query("select * from discount_coupons_to_orders WHERE orders_id = " . $_POST['invoice'] . " limit 1");
		if (tep_db_num_rows($discount_to_order_query) == 0) {
			//Let's see if the order total table has a discount code in it
			$discount_query = tep_db_query("select * from " . TABLE_ORDERS_TOTAL . " WHERE orders_id = " . $_POST['invoice'] . " and class = 'ot_discount_coupon' limit 1");
			if (tep_db_num_rows($discount_query) > 0) {
				$discount = tep_db_fetch_array($discount_query);
				//Fish the code out of the entry - Title is usually in the format of 'Discount Coupon XXXXXX Applied:'
				$coupon = str_replace("Discount Coupon ", "", $discount['title']);
				$coupon = str_replace(" applied:", "", $coupon);

				$sql_data_array = array( 'coupons_id' => $coupon,
										 'orders_id' => $_POST['invoice'] );
				tep_db_perform( 'discount_coupons_to_orders', $sql_data_array );
			}
		}
		// UKSB End Apply Discount Coupon

find:

         $comment_status .= ", \n" . PAYPAL_ADDRESS . ": " . $_POST['address_name'] . ", " . $_POST['address_street'] . ", " . $_POST['address_city'] . ", " . $_POST['address_zip'] . ", " . $_POST['address_state'] . ", " . $_POST['address_country'] . ", " . $_POST['address_country_code'] . ", " . $_POST['address_status'];


Add after:

	  // UKSB Apply discount coupon
		//Check to see if the discount coupon has already been applied to the order
		$discount_to_order_query = tep_db_query("select * from discount_coupons_to_orders WHERE orders_id = " . $_POST['invoice'] . " limit 1");
		if (tep_db_num_rows($discount_to_order_query) == 0) {
			//Let's see if the order total table has a discount code in it
			$discount_query = tep_db_query("select * from " . TABLE_ORDERS_TOTAL . " WHERE orders_id = " . $_POST['invoice'] . " and class = 'ot_discount_coupon' limit 1");
			if (tep_db_num_rows($discount_query) > 0) {
				$discount = tep_db_fetch_array($discount_query);
				//Fish the code out of the entry - Title is usually in the format of 'Discount Coupon XXXXXX Applied:'
				$coupon = str_replace("Discount Coupon ", "", $discount['title']);
				$coupon = str_replace(" applied:", "", $coupon);

				$sql_data_array = array( 'coupons_id' => $coupon,
										 'orders_id' => $_POST['invoice'] );
				tep_db_perform( 'discount_coupons_to_orders', $sql_data_array );
			}
		}
		// UKSB End Apply Discount Coupon

 

As you can see above, I marked the coupon as used if the payment was authorised as pending or completed. It is up to you if you don't want to do that - Just don't do the first find/add-after.

 

You can use this hack/fix for other payment methods too which use a similar method of IPN Callback. Just be careful with the order_id post variable as this probably will be called something else.

 

It is a dirty hack, but it works in the absence of a better solution

 

Use at your own risk.

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