Jump to content
kgt

[Contribution] Discount Coupon Codes

Recommended Posts

When the instructions say to add code, they do mean you need to add the code between the opening

 

<?php

 

and closing

 

?>

 

tags. Specifically, take a look at catalog/includes/database_tables.php and make sure there is nothing after the ?> tag.

Share this post


Link to post
Share on other sites
When the instructions say to add code, they do mean you need to add the code between the opening

 

<?php

 

and closing

 

?>

 

tags. Specifically, take a look at catalog/includes/database_tables.php and make sure there is nothing after the ?> tag.

 

 

Oops - what an idiot.! Thanks for your fast response cheers J

Share this post


Link to post
Share on other sites
Oops - what an idiot.! Thanks for your fast response cheers J

 

 

Hi I have gone back and corrected my errors but still get this Warning - any ideas Thanks J

 

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/xxxxxxx/public_html/catalog/includes/database_tables.php:64) in /home/xxxxxxx/public_html/catalog/includes/functions/sessions.php on line 97

Share this post


Link to post
Share on other sites
Hi I have gone back and corrected my errors but still get this Warning - any ideas Thanks J

 

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/xxxxxxx/public_html/catalog/includes/database_tables.php:64) in /home/xxxxxxx/public_html/catalog/includes/functions/sessions.php on line 97

 

There can be NOTHING after the ?> tag. No spaces, no line breaks.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites

Im having a bit of trouble with this contrb.

 

Everything works wonderful except one BIG thing.

 

When I enter in a percentage it adds zeros to it and makes it HUNDREDS of percents.

 

Say I enter 5 for 5 percent, it adds 2 zeros and makes it 500%.

 

However when I choose to edit the coupon it shows up in the box as 5.00

 

 

The decimal point is getting removed somwher, (i think)

 

Any help would be appreciated.

 

Thanks

Share this post


Link to post
Share on other sites
Im having a bit of trouble with this contrb.

 

Everything works wonderful except one BIG thing.

 

When I enter in a percentage it adds zeros to it and makes it HUNDREDS of percents.

 

Say I enter 5 for 5 percent, it adds 2 zeros and makes it 500%.

 

However when I choose to edit the coupon it shows up in the box as 5.00

The decimal point is getting removed somwher, (i think)

 

Any help would be appreciated.

 

Thanks

You mean it is displaying in the admin as 500% in the admin. Yes, I get that also. It is rather troubling. I'm going to try and redo mine as it errors at checkout,, there is a slash missing in the "catalog/includes/modules/order_total/ot_discount_coupon.php" file

so its pulling "catalogincludes/classes/discount_coupon.php" instead of "catalog/includes/classes/discount_coupon.php"

 

I'll let you know if it affects the final order...

 

Tapuahk

Share this post


Link to post
Share on other sites
Im having a bit of trouble with this contrb.

 

Everything works wonderful except one BIG thing.

 

When I enter in a percentage it adds zeros to it and makes it HUNDREDS of percents.

 

Say I enter 5 for 5 percent, it adds 2 zeros and makes it 500%.

 

However when I choose to edit the coupon it shows up in the box as 5.00

The decimal point is getting removed somwher, (i think)

 

Any help would be appreciated.

 

Thanks

 

 

Hi, I am using the discount coupons, and my understanding is that if you want 5%, you have to enter it as .05, not 5. As it appears 1 = 100%

 

David

Share this post


Link to post
Share on other sites
You mean it is displaying in the admin as 500% in the admin. Yes, I get that also. It is rather troubling. I'm going to try and redo mine as it errors at checkout,, there is a slash missing in the "catalog/includes/modules/order_total/ot_discount_coupon.php" file

so its pulling "catalogincludes/classes/discount_coupon.php" instead of "catalog/includes/classes/discount_coupon.php"

 

I'll let you know if it affects the final order...

 

Tapuahk

 

 

Fixed my problem, I added the slash in the definition of DIR_FS_CATALOG in the configure.php.

 

Yes, it does affect the total discount , you need to enter discount in decimal format 5% is equal to .05

 

entering 5 is same as 500%.

 

 

It works great that way.

 

Tapuahk

Share this post


Link to post
Share on other sites

Hi

 

Great contribution, works well.

 

I have a question. I want to setup a "Twins Club" where if a member with a coupon number buys 2 or more products they get a 15% discount. Is there anyway to have a mimimum amount of products instead of a minimum dollar value?

 

Regards

 

Nick

Share this post


Link to post
Share on other sites
There can be NOTHING after the ?> tag. No spaces, no line breaks.

 

 

Hi kgt

 

Thank you for your help - that is all sorted.

 

I have set up a discount code & get this message when I try to test purchase using the code any ideas. Thks John

 

Fatal error: Cannot instantiate non-existent class: discount_coupon in /home/sherpas1/public_html/catalog/checkout_confirmation.php on line 69

Share this post


Link to post
Share on other sites
I have a question. I want to setup a "Twins Club" where if a member with a coupon number buys 2 or more products they get a 15% discount. Is there anyway to have a mimimum amount of products instead of a minimum dollar value?

 

Change the check_coupons_min_order() function in includes/classes/discount_coupon.php to:

 

function check_coupons_min_order() {
		/*global $order, $currencies;
  //if we display the subtotal without the discount applied, then just compare the subtotal to the minimum order
		if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'false' && $this->coupon['coupons_min_order'] > $order->info['subtotal'] ) {
			$this->error_message[] = sprintf( ENTRY_DISCOUNT_COUPON_MIN_ERROR, $currencies->format( $this->coupon['coupons_min_order'], true, $order->info['currency'], $order->info['currency_value'] ) );
		//if we display the subtotal with the discount applied, then we need to compare the subtotal with the discount added back in to the minimum order
		} else if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'true' ) {
		  $subtotal = $order->info['subtotal'];
	  foreach( $order->info['applied_discount'] as $discount ) {
				$subtotal += $discount;
			}
			if( $this->coupon['coupons_min_order'] > $subtotal ) $this->error_message[] = sprintf( ENTRY_DISCOUNT_COUPON_MIN_ERROR, $currencies->format( $this->coupon['coupons_min_order'], true, $order->info['currency'], $order->info['currency_value'] ) );
		}*/
		global $cart;
		$num_products = $cart->count_contents();
		if( $this->coupon['coupons_min_order'] > $num_products ) $this->error_message[] = sprintf( ENTRY_DISCOUNT_COUPON_MIN_ERROR, $this->coupon['coupons_min_order'] );
	}

 

Also, edit includes/languages/english.php:

 

define('ENTRY_DISCOUNT_COUPON_MIN_ERROR', 'The minimum order total for this coupon is %s');

 

Make the error message something like:

 

define('ENTRY_DISCOUNT_COUPON_MIN_ERROR', 'You must have %s or more items to qualify for this discount.');

 

 

 

My example is using the order minimum field to do this. This means it will replace the dollar minimum with a count minimum.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Hi kgt

 

Thank you for your help - that is all sorted.

 

I have set up a discount code & get this message when I try to test purchase using the code any ideas. Thks John

 

Fatal error: Cannot instantiate non-existent class: discount_coupon in /home/sherpas1/public_html/catalog/checkout_confirmation.php on line 69

 

 

Make sure this code:

 

  //kgt - discount coupons
 if( tep_not_null( $HTTP_POST_VARS['coupon'] ) ) { //if they have entered something in the coupon field
$this_coupon = new discount_coupon( tep_db_prepare_input( $HTTP_POST_VARS['coupon'] ) );
$this_coupon->verify_code();
//print_r( $this_coupon ); //use this to debug coupon object problems
	if( !$this_coupon->is_errors() ) { //if we have passed all tests (no error message), make sure we still meet free shipping requirements, if any
		if( $this_coupon->is_recalc_shipping() ) tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( ENTRY_DISCOUNT_COUPON_FREE_SHIPPING_ERROR ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method
	} else {
		if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon'); //remove the coupon from the session
		tep_redirect( tep_href_link( FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode( implode( ' ', $this_coupon->error_message ) ), 'SSL' ) ); //redirect to the payment page
	}
} else { //if the coupon field is empty, unregister the coupon from the session
	if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon');
}
//end kgt - discount coupons

 

appears AFTER this code:

 

  require(DIR_WS_CLASSES . 'order.php');
 $order = new order;

 

in checkout_confirmation.php. Also make sure you have uploaded the file includes/classes/discount_coupon.php.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites

i have installed the contribution and it works perfectly ... :)

 

at present the discount is being applied during the checkout phase ... but is there a way of applying the discount to the catalog so it shows against product prices and in the shopping cart 'infobox' while the customer is shopping. i was hoping to introduce an input field on the main page or customer login page but have no idea if this is possible or not.

Share this post


Link to post
Share on other sites
i have installed the contribution and it works perfectly ... :)

 

at present the discount is being applied during the checkout phase ... but is there a way of applying the discount to the catalog so it shows against product prices and in the shopping cart 'infobox' while the customer is shopping. i was hoping to introduce an input field on the main page or customer login page but have no idea if this is possible or not.

 

 

If you're looking for something like that, try starting with a contribution that is more designed for pricing vs. order discount. This contribution was written as an order total module, which means it would be almost as much work getting it to work like you want than if someone just started from scratch.

 

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

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

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


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
If you're looking for something like that, try starting with a contribution that is more designed for pricing vs. order discount. This contribution was written as an order total module, which means it would be almost as much work getting it to work like you want than if someone just started from scratch.

 

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

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

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

 

many thanks kgt .. I'll go and have a closer look at what they offer ... but on first glance they don't appear to operate a voucher system.

Share this post


Link to post
Share on other sites
many thanks kgt .. I'll go and have a closer look at what they offer ... but on first glance they don't appear to operate a voucher system.

 

 

None of them do (as far as I know). But I think that starting with one of those will take less time than starting with an order discount module. The framework should basically be there (variable pricing depending on customer) - you just need to add the field to accept a code and populate the customer's discount field/table with the applicable discount. I guess after they log off or log in again without a code, you'd need to purge the discount table/field so that they don't always have a discount even when they don't enter a code.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites

Thank you for a great contribution!

 

I have installed the latest version, but I am having to issues, that will most probably be my mistake.

 

1) If you have mutliple payment types, the coupon code box is below each.

a) only the bottom one seems to be active.

2) If applying a pecentage amount ie: .10 (10%) not a fixed amount I am not gettin the correct percentage ( on a $51.98 purchase I am showing a discount of $9.90 instead of $5.20

 

Regards,

 

Steve

Share this post


Link to post
Share on other sites
Thank you for a great contribution!

 

I have installed the latest version, but I am having to issues, that will most probably be my mistake.

 

1) If you have mutliple payment types, the coupon code box is below each.

a) only the bottom one seems to be active.

2) If applying a pecentage amount ie: .10 (10%) not a fixed amount I am not gettin the correct percentage ( on a $51.98 purchase I am showing a discount of $9.90 instead of $5.20

 

Regards,

 

Steve

 

1) Compare the checkout_payment.php file in the contribution zip with the one you have. I think you probably just got the code for the text box inserted in the wrong place. (The bottom one seems to be "active" while the top is not because they would have the same name. The later value overwrites the earlier one, even if it is empty.)

 

2) In includes/modules/order_total/ot_discount_coupon.php, you should find the following around line 33:

 

//print_r( $order ); //kgt - use this to debug order object contents

//print_r( $this->coupon ); //kgt - use this to debug coupon object contents

 

Uncomment both of those lines then enter your coupon code in the checkout process. The order confirmation screen will output debugging information about the order object. Please send me that output in a PM or email and I will take a look at it.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
1) Compare the checkout_payment.php file in the contribution zip with the one you have. I think you probably just got the code for the text box inserted in the wrong place. (The bottom one seems to be "active" while the top is not because they would have the same name. The later value overwrites the earlier one, even if it is empty.)

 

2) In includes/modules/order_total/ot_discount_coupon.php, you should find the following around line 33:

 

//print_r( $order ); //kgt - use this to debug order object contents

//print_r( $this->coupon ); //kgt - use this to debug coupon object contents

 

Uncomment both of those lines then enter your coupon code in the checkout process. The order confirmation screen will output debugging information about the order object. Please send me that output in a PM or email and I will take a look at it.

 

Thank you for the hint.

 

1) it was in the wrong place.

 

2) here is the info:

 

order Object ( [info] => Array ( [order_status] => 1 [currency] => USD [currency_value] => 1.00000000 [payment_method] => Check/Money Order [cc_type] => [cc_owner] => [cc_number] => [cc_expires] => [shipping_method] => Flat Rate (Best Way) [shipping_cost] => 10.00 [subtotal] => 61.06 [tax] => 0 [tax_groups] => Array ( [unknown tax rate] => 0 ) [coupon] => PGH [applied_discount] => Array ( [unknown tax rate] => 9.91 ) [comments] => [total] => 71.06 ) [totals] => Array ( ) [products] => Array ( [0] => Array ( [qty] => 1 [name] => Jasmine Flowering Display Tea Sampler [model] => gt020 [tax] => 0 [tax_description] => Unknown tax rate [price] => 24.9900 [final_price] => 24.99 [weight] => 0.25 [id] => 57 ) [1] => Array ( [qty] => 2 [name] => IngenuiTEA 32oz Tea Maker [model] => adit32 [tax] => 0 [tax_description] => Unknown tax rate [price] => 22.9900 [final_price] => 22.99 [weight] => 0.00 [id] => 54 ) ) [customer] => Array ( [firstname] => Test [lastname] => Test [company] => [street_address] => 123 Test [suburb] => [city] => Doral [postcode] => 33172 [state] => Florida [zone_id] => 18 [country] => Array ( [id] => 223 [title] => United States [iso_code_2] => US [iso_code_3] => USA ) [format_id] => 2 [telephone] => 305-123-4578 [email_address] => stgold@cbs.com ) [delivery] => Array ( [firstname] => Test [lastname] => Test [company] => [street_address] => 123 Test [suburb] => [city] => Doral [postcode] => 33172 [state] => Florida [zone_id] => 18 [country] => Array ( [id] => 223 [title] => United States [iso_code_2] => US [iso_code_3] => USA ) [country_id] => 223 [format_id] => 2 ) [content_type] => physical [billing] => Array ( [firstname] => Test [lastname] => Test [company] => [street_address] => 123 Test [suburb] => [city] => Doral [postcode] => 33172 [state] => Florida [zone_id] => 18 [country] => Array ( [id] => 223 [title] => United States [iso_code_2] => US [iso_code_3] => USA ) [country_id] => 223 [format_id] => 2 ) ) discount_coupon Object (

 => PGH [error_message] => Array ( ) [coupon] => Array ( [coupons_discount_percent] => 0.1000 [coupons_description] => PGH Employee Dicount [coupons_max_use] => 0 [coupons_min_order] => 25.0000 [coupons_max_order] => 99.0000 [coupons_number_available] => 0 ) )

 

Thank You

 

Steve

Share this post


Link to post
Share on other sites
Make sure this code:

 

  //kgt - discount coupons
 if( tep_not_null( $HTTP_POST_VARS['coupon'] ) ) { //if they have entered something in the coupon field
$this_coupon = new discount_coupon( tep_db_prepare_input( $HTTP_POST_VARS['coupon'] ) );
$this_coupon->verify_code();
//print_r( $this_coupon ); //use this to debug coupon object problems
	if( !$this_coupon->is_errors() ) { //if we have passed all tests (no error message), make sure we still meet free shipping requirements, if any
		if( $this_coupon->is_recalc_shipping() ) tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( ENTRY_DISCOUNT_COUPON_FREE_SHIPPING_ERROR ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method
	} else {
		if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon'); //remove the coupon from the session
		tep_redirect( tep_href_link( FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode( implode( ' ', $this_coupon->error_message ) ), 'SSL' ) ); //redirect to the payment page
	}
} else { //if the coupon field is empty, unregister the coupon from the session
	if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon');
}
//end kgt - discount coupons

 

appears AFTER this code:

 

  require(DIR_WS_CLASSES . 'order.php');
 $order = new order;

 

in checkout_confirmation.php. Also make sure you have uploaded the file includes/classes/discount_coupon.php.

 

 

Hi Kristen

 

In the contribution it says to add it after

 

if (is_array($payment_modules->modules)) {

$payment_modules->pre_confirmation_check();

}

 

I have also uploaded includes/classes/discount_coupon.php.

 

 

Any other suggestions J

Share this post


Link to post
Share on other sites
Hi Kristen

 

In the contribution it says to add it after

 

if (is_array($payment_modules->modules)) {

$payment_modules->pre_confirmation_check();

}

 

I have also uploaded includes/classes/discount_coupon.php.

Any other suggestions J

 

That's where you add the code. I am asking you to be sure that the creation of the order object happens somewhere before the code that is inserted for this contribution. Some other contributions move the placement of the creation of the order object to later in the file. You must ensure that

 

  require(DIR_WS_CLASSES . 'order.php');
 $order = new order;

 

happens before

 

  //kgt - discount coupons
 if( tep_not_null( $HTTP_POST_VARS['coupon'] ) ) { //if they have entered something in the coupon field
$this_coupon = new discount_coupon( tep_db_prepare_input( $HTTP_POST_VARS['coupon'] ) );
$this_coupon->verify_code();
//print_r( $this_coupon ); //use this to debug coupon object problems
	if( !$this_coupon->is_errors() ) { //if we have passed all tests (no error message), make sure we still meet free shipping requirements, if any
		if( $this_coupon->is_recalc_shipping() ) tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( ENTRY_DISCOUNT_COUPON_FREE_SHIPPING_ERROR ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method
	} else {
		if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon'); //remove the coupon from the session
		tep_redirect( tep_href_link( FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode( implode( ' ', $this_coupon->error_message ) ), 'SSL' ) ); //redirect to the payment page
	}
} else { //if the coupon field is empty, unregister the coupon from the session
	if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon');
}
//end kgt - discount coupons


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Thank you for the hint.

 

1) it was in the wrong place.

 

2) here is the info:

 

order Object ( [info] => Array ( [order_status] => 1 [currency] => USD [currency_value] => 1.00000000 [payment_method] => Check/Money Order [cc_type] => [cc_owner] => [cc_number] => [cc_expires] => [shipping_method] => Flat Rate (Best Way) [shipping_cost] => 10.00 [subtotal] => 61.06 [tax] => 0 [tax_groups] => Array ( [unknown tax rate] => 0 ) [coupon] => PGH [applied_discount] => Array ( [unknown tax rate] => 9.91 ) [comments] => [total] => 71.06 ) [totals] => Array ( ) [products] => Array ( [0] => Array ( [qty] => 1 [name] => Jasmine Flowering Display Tea Sampler [model] => gt020 [tax] => 0 [tax_description] => Unknown tax rate [price] => 24.9900...

 

 

These order totals don't add up at all! Did you upgrade to the latest version or did you install it from scratch? If you upgraded, from which version did you upgrade? Double check that you've made the correct changes to includes/classes/order.php, especially from around line 252 to the end of the file.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
That's where you add the code. I am asking you to be sure that the creation of the order object happens somewhere before the code that is inserted for this contribution. Some other contributions move the placement of the creation of the order object to later in the file. You must ensure that

 

  require(DIR_WS_CLASSES . 'order.php');
 $order = new order;

 

happens before

 

  //kgt - discount coupons
 if( tep_not_null( $HTTP_POST_VARS['coupon'] ) ) { //if they have entered something in the coupon field
$this_coupon = new discount_coupon( tep_db_prepare_input( $HTTP_POST_VARS['coupon'] ) );
$this_coupon->verify_code();
//print_r( $this_coupon ); //use this to debug coupon object problems
	if( !$this_coupon->is_errors() ) { //if we have passed all tests (no error message), make sure we still meet free shipping requirements, if any
		if( $this_coupon->is_recalc_shipping() ) tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( ENTRY_DISCOUNT_COUPON_FREE_SHIPPING_ERROR ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method
	} else {
		if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon'); //remove the coupon from the session
		tep_redirect( tep_href_link( FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode( implode( ' ', $this_coupon->error_message ) ), 'SSL' ) ); //redirect to the payment page
	}
} else { //if the coupon field is empty, unregister the coupon from the session
	if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon');
}
//end kgt - discount coupons

 

Hi Kristen

 

Thank you for your help and patience - I seem to have entered it correctly.

 

Here is the catalog/checkout.php file and the two changes made are either side of

  require(DIR_WS_CLASSES . 'order.php');
 $order = new order;

 

which seems ok if it is just the longer of element of code that needs to be after it.

 

Apologies for the time this is taking J

 

<?php
/*
 $Id: checkout_confirmation.php,v 1.139 2003/06/11 17:34:53 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 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(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_PAYMENT));
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));
 }

// 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'));
}
 }

// 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'));
 }

 if (!tep_session_is_registered('payment')) tep_session_register('payment');
 if (isset($HTTP_POST_VARS['payment'])) $payment = $HTTP_POST_VARS['payment'];

 if (!tep_session_is_registered('comments')) tep_session_register('comments');
 if (tep_not_null($HTTP_POST_VARS['comments'])) {
$comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);
 } //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 // load the selected payment module
 require(DIR_WS_CLASSES . 'payment.php');
 $payment_modules = new payment($payment);

require(DIR_WS_CLASSES . 'order.php');
 $order = new order;
 $payment_modules->update_status();

 if ( ( is_array($payment_modules->modules) && (sizeof($payment_modules->modules) > 1) && !is_object($$payment) ) || (is_object($$payment) && ($$payment->enabled == false)) ) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_NO_PAYMENT_MODULE_SELECTED), 'SSL'));
 }

 if (is_array($payment_modules->modules)) {
$payment_modules->pre_confirmation_check();
 } //kgt - discount coupons
  if( tep_not_null( $HTTP_POST_VARS['coupon'] ) ) { //if they have entered something in the coupon field
	$this_coupon = new discount_coupon( tep_db_prepare_input( $HTTP_POST_VARS['coupon'] ) );
	$this_coupon->verify_code();
	//print_r( $this_coupon ); //use this to debug coupon object problems
		if( !$this_coupon->is_errors() ) { //if we have passed all tests (no error message), make sure we still meet free shipping requirements, if any
			if( $this_coupon->is_recalc_shipping() ) tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( ENTRY_DISCOUNT_COUPON_FREE_SHIPPING_ERROR ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method
		} else {
			if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon'); //remove the coupon from the session
			tep_redirect( tep_href_link( FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode( implode( ' ', $this_coupon->error_message ) ), 'SSL' ) ); //redirect to the payment page
		}
	} else { //if the coupon field is empty, unregister the coupon from the session
		if( tep_session_is_registered('coupon') ) tep_session_unregister('coupon');
	}
	//end kgt - discount coupons  // load the selected shipping module
 require(DIR_WS_CLASSES . 'shipping.php');
 $shipping_modules = new shipping($shipping);

 require(DIR_WS_CLASSES . 'order_total.php');
 $order_total_modules = new order_total;

// Stock Check
 $any_out_of_stock = false;
 if (STOCK_CHECK == 'true') {
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
  if (tep_check_stock($order->products[$i]['id'], $order->products[$i]['qty'])) {
	$any_out_of_stock = true;
  }
}
// Out of Stock
if ( (STOCK_ALLOW_CHECKOUT != 'true') && ($any_out_of_stock == true) ) {
  tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
}
 }

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

 $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
 $breadcrumb->add(NAVBAR_TITLE_2);
?>
<!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; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
 <tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
</table></td>
<!-- body_text //-->
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
	  <tr>
		<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
		<td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_confirmation.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
  <tr>
	<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
	  <tr class="infoBoxContents">
<?php
 if ($sendto != false) {
?>
		<td width="30%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
		  <tr>
			<td class="main"><?php echo '<b>' . HEADING_DELIVERY_ADDRESS . '</b> <a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL') . '"><span class="orderEdit">(' . TEXT_EDIT . ')</span></a>'; ?></td>
		  </tr>
		  <tr>
			<td class="main"><?php echo tep_address_format($order->delivery['format_id'], $order->delivery, 1, ' ', '<br>'); ?></td>
		  </tr>
<?php
if ($order->info['shipping_method']) {
?>
		  <tr>
			<td class="main"><?php echo '<b>' . HEADING_SHIPPING_METHOD . '</b> <a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '"><span class="orderEdit">(' . TEXT_EDIT . ')</span></a>'; ?></td>
		  </tr>
		  <tr>
			<td class="main"><?php echo $order->info['shipping_method']; ?></td>
		  </tr>
<?php
}
?>
		</table></td>
<?php
 }
?>
		<td width="<?php echo (($sendto != false) ? '70%' : '100%'); ?>" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr>
			<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
 if (sizeof($order->info['tax_groups']) > 1) {
?>
			  <tr>
				<td class="main" colspan="2"><?php echo '<b>' . HEADING_PRODUCTS . '</b> <a href="' . tep_href_link(FILENAME_SHOPPING_CART) . '"><span class="orderEdit">(' . TEXT_EDIT . ')</span></a>'; ?></td>
				<td class="smallText" align="right"><b><?php echo HEADING_TAX; ?></b></td>
				<td class="smallText" align="right"><b><?php echo HEADING_TOTAL; ?></b></td>
			  </tr>
<?php
 } else {
?>
			  <tr>
				<td class="main" colspan="3"><?php echo '<b>' . HEADING_PRODUCTS . '</b> <a href="' . tep_href_link(FILENAME_SHOPPING_CART) . '"><span class="orderEdit">(' . TEXT_EDIT . ')</span></a>'; ?></td>
			  </tr>
<?php
 }

 for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
echo '		  <tr>' . "\n" .
	 '			<td class="main" align="right" valign="top" width="30">' . $order->products[$i]['qty'] . '?x</td>' . "\n" .
	 '			<td class="main" valign="top">' . $order->products[$i]['name'];

if (STOCK_CHECK == 'true') {
  echo tep_check_stock($order->products[$i]['id'], $order->products[$i]['qty']);
}

if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
  for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
	echo '<br><nobr><small>?<i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'] . '</i></small></nobr>';
  }
}

echo '</td>' . "\n";

if (sizeof($order->info['tax_groups']) > 1) echo '			<td class="main" valign="top" align="right">' . tep_display_tax_value($order->products[$i]['tax']) . '%</td>' . "\n";

echo '			<td class="main" align="right" valign="top">' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . '</td>' . "\n" .
	 '		  </tr>' . "\n";
 }
?>
			</table></td>
		  </tr>
		</table></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
  <tr>
	<td class="main"><b><?php echo HEADING_BILLING_INFORMATION; ?></b></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
  <tr>
	<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
	  <tr class="infoBoxContents">
		<td width="30%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
		  <tr>
			<td class="main"><?php echo '<b>' . HEADING_BILLING_ADDRESS . '</b> <a href="' . tep_href_link(FILENAME_CHECKOUT_PAYMENT_ADDRESS, '', 'SSL') . '"><span class="orderEdit">(' . TEXT_EDIT . ')</span></a>'; ?></td>
		  </tr>
		  <tr>
			<td class="main"><?php echo tep_address_format($order->billing['format_id'], $order->billing, 1, ' ', '<br>'); ?></td>
		  </tr>
		  <tr>
			<td class="main"><?php echo '<b>' . HEADING_PAYMENT_METHOD . '</b> <a href="' . tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL') . '"><span class="orderEdit">(' . TEXT_EDIT . ')</span></a>'; ?></td>
		  </tr>
		  <tr>
			<td class="main"><?php echo $order->info['payment_method']; ?></td>
		  </tr>
		</table></td>
		<td width="70%" valign="top" align="right"><table border="0" cellspacing="0" cellpadding="2">
<?php
 if (MODULE_ORDER_TOTAL_INSTALLED) {
$order_total_modules->process();
echo $order_total_modules->output();
 }
?>
		</table></td>
	  </tr>
	</table></td>
  </tr>
<?php
 if (is_array($payment_modules->modules)) {
if ($confirmation = $payment_modules->confirmation()) {
?>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
  <tr>
	<td class="main"><b><?php echo HEADING_PAYMENT_INFORMATION; ?></b></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
  <tr>
	<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
	  <tr class="infoBoxContents">
		<td><table border="0" cellspacing="0" cellpadding="2">
		  <tr>
			<td class="main" colspan="4"><?php echo $confirmation['title']; ?></td>
		  </tr>
<?php
  for ($i=0, $n=sizeof($confirmation['fields']); $i<$n; $i++) {
?>
		  <tr>
			<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
			<td class="main"><?php echo $confirmation['fields'][$i]['title']; ?></td>
			<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
			<td class="main"><?php echo $confirmation['fields'][$i]['field']; ?></td>
		  </tr>
<?php
  }
?>
		</table></td>
	  </tr>
	</table></td>
  </tr>
<?php
}
 }
?>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
<?php
 if (tep_not_null($order->info['comments'])) {
?>
  <tr>
	<td class="main"><?php echo '<b>' . HEADING_ORDER_COMMENTS . '</b> <a href="' . tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL') . '"><span class="orderEdit">(' . TEXT_EDIT . ')</span></a>'; ?></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
  <tr>
	<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
	  <tr class="infoBoxContents">
		<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
		  <tr>
			<td class="main"><?php echo nl2br(tep_output_string_protected($order->info['comments'])) . tep_draw_hidden_field('comments', $order->info['comments']); ?></td>
		  </tr>
		</table></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
<?php
 }
?>
  <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
	  <tr>
		<td align="right" class="main">
<?php
 if (isset($$payment->form_action_url)) {
$form_action_url = $$payment->form_action_url;
 } else {
$form_action_url = tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL');
 }

 echo tep_draw_form('checkout_confirmation', $form_action_url, 'post');

 if (is_array($payment_modules->modules)) {
echo $payment_modules->process_button();
 }

 echo tep_image_submit('button_confirm_order.gif', IMAGE_BUTTON_CONFIRM_ORDER) . '</form>' . "\n";
?>
		</td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
  <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
	  <tr>
		<td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="50%" align="right"><?php echo tep_draw_separator('pixel_silver.gif', '1', '5'); ?></td>
			<td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
		  </tr>
		</table></td>
		<td width="25%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
		<td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
			<td><?php echo tep_image(DIR_WS_IMAGES . 'checkout_bullet.gif'); ?></td>
			<td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
		  </tr>
		</table></td>
		<td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
			<td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '1', '5'); ?></td>
		  </tr>
		</table></td>
	  </tr>
	  <tr>
		<td align="center" width="25%" class="checkoutBarFrom"><?php echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '" class="checkoutBarFrom">' . CHECKOUT_BAR_DELIVERY . '</a>'; ?></td>
		<td align="center" width="25%" class="checkoutBarFrom"><?php echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL') . '" class="checkoutBarFrom">' . CHECKOUT_BAR_PAYMENT . '</a>'; ?></td>
		<td align="center" width="25%" class="checkoutBarCurrent"><?php echo CHECKOUT_BAR_CONFIRMATION; ?></td>
		<td align="center" width="25%" class="checkoutBarTo"><?php echo CHECKOUT_BAR_FINISHED; ?></td>
	  </tr>
	</table></td>
  </tr>
</table></td>
<!-- body_text_eof //-->
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
</table></td>
 </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Share this post


Link to post
Share on other sites
Hi Kristen

 

Thank you for your help and patience - I seem to have entered it correctly.

 

Here is the catalog/checkout.php file and the two changes made are either side of

  require(DIR_WS_CLASSES . 'order.php');
 $order = new order;

 

which seems ok if it is just the longer of element of code that needs to be after it.

 

 

Your checkout_confirmation.php is perfectly correct.

 

What about includes/classes/order.php? That's where the class gets included and defined.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Your checkout_confirmation.php is perfectly correct.

 

What about includes/classes/order.php? That's where the class gets included and defined.

 

 

Hi Kristen you were right I had missed adding the first new element of code - this i have now done but get this error

 

Parse error: syntax error, unexpected T_IF, expecting ')' in /home/sherpas1/public_html/catalog/includes/classes/order.php on line 168

 

I have looked through the other amendments but cannot see where I might have gone wrong.

 

Here is the Order.php file

 

<?php
/*
 $Id: order.php,v 1.33 2003/06/09 22:25:35 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 class order {
var $info, $totals, $products, $customer, $delivery, $content_type;

function order($order_id = '') {
  $this->info = array();
  $this->totals = array();
  $this->products = array();
  $this->customer = array();
  $this->delivery = array();

  if (tep_not_null($order_id)) {
	$this->query($order_id);
  } else {
	$this->cart();
  }
}

function query($order_id) {
  global $languages_id;

  $order_id = tep_db_prepare_input($order_id);

  $order_query = tep_db_query("select customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value, date_purchased, orders_status, last_modified from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
  $order = tep_db_fetch_array($order_query);

  $totals_query = tep_db_query("select title, text from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' order by sort_order");
  while ($totals = tep_db_fetch_array($totals_query)) {
	$this->totals[] = array('title' => $totals['title'],
							'text' => $totals['text']);
  }

  $order_total_query = tep_db_query("select text from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_total'");
  $order_total = tep_db_fetch_array($order_total_query);

  $shipping_method_query = tep_db_query("select title from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' and class = 'ot_shipping'");
  $shipping_method = tep_db_fetch_array($shipping_method_query);

  $order_status_query = tep_db_query("select orders_status_name from " . TABLE_ORDERS_STATUS . " where orders_status_id = '" . $order['orders_status'] . "' and language_id = '" . (int)$languages_id . "'");
  $order_status = tep_db_fetch_array($order_status_query);

  $this->info = array('currency' => $order['currency'],
					  'currency_value' => $order['currency_value'],
					  'payment_method' => $order['payment_method'],
					  'cc_type' => $order['cc_type'],
					  'cc_owner' => $order['cc_owner'],
					  'cc_number' => $order['cc_number'],
					  'cc_expires' => $order['cc_expires'],
					  'date_purchased' => $order['date_purchased'],
					  'orders_status' => $order_status['orders_status_name'],
					  'last_modified' => $order['last_modified'],
					  'total' => strip_tags($order_total['text']),
					  'shipping_method' => ((substr($shipping_method['title'], -1) == ':') ? substr(strip_tags($shipping_method['title']), 0, -1) : strip_tags($shipping_method['title'])));

  $this->customer = array('id' => $order['customers_id'],
						  'name' => $order['customers_name'],
						  'company' => $order['customers_company'],
						  'street_address' => $order['customers_street_address'],
						  'suburb' => $order['customers_suburb'],
						  'city' => $order['customers_city'],
						  'postcode' => $order['customers_postcode'],
						  'state' => $order['customers_state'],
						  'country' => $order['customers_country'],
						  'format_id' => $order['customers_address_format_id'],
						  'telephone' => $order['customers_telephone'],
						  'email_address' => $order['customers_email_address']);

  $this->delivery = array('name' => $order['delivery_name'],
						  'company' => $order['delivery_company'],
						  'street_address' => $order['delivery_street_address'],
						  'suburb' => $order['delivery_suburb'],
						  'city' => $order['delivery_city'],
						  'postcode' => $order['delivery_postcode'],
						  'state' => $order['delivery_state'],
						  'country' => $order['delivery_country'],
						  'format_id' => $order['delivery_address_format_id']);

  if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
	$this->delivery = false;
  }

  $this->billing = array('name' => $order['billing_name'],
						 'company' => $order['billing_company'],
						 'street_address' => $order['billing_street_address'],
						 'suburb' => $order['billing_suburb'],
						 'city' => $order['billing_city'],
						 'postcode' => $order['billing_postcode'],
						 'state' => $order['billing_state'],
						 'country' => $order['billing_country'],
						 'format_id' => $order['billing_address_format_id']);

  $index = 0;
  $orders_products_query = tep_db_query("select orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
  while ($orders_products = tep_db_fetch_array($orders_products_query)) {
	$this->products[$index] = array('qty' => $orders_products['products_quantity'],
								'id' => $orders_products['products_id'],
									'name' => $orders_products['products_name'],
									'model' => $orders_products['products_model'],
									'tax' => $orders_products['products_tax'],
									'price' => $orders_products['products_price'],
									'final_price' => $orders_products['final_price']);

	$subindex = 0;
	$attributes_query = tep_db_query("select products_options, products_options_values, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'");
	if (tep_db_num_rows($attributes_query)) {
	  while ($attributes = tep_db_fetch_array($attributes_query)) {
		$this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'],
																 'value' => $attributes['products_options_values'],
																 'prefix' => $attributes['price_prefix'],
																 'price' => $attributes['options_values_price']);

		$subindex++;
	  }
	}

	$this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1';

	$index++;
  }
}

function cart() {
  global $customer_id, $sendto, $billto, $cart, $languages_id, $currency, $currencies, $shipping, $payment;

  $this->content_type = $cart->get_content_type();

  $customer_address_query = tep_db_query("select c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_email_address, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, co.countries_id, co.countries_name, co.countries_iso_code_2, co.countries_iso_code_3, co.address_format_id, ab.entry_state from " . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id) where c.customers_id = '" . (int)$customer_id . "' and ab.customers_id = '" . (int)$customer_id . "' and c.customers_default_address_id = ab.address_book_id");
  $customer_address = tep_db_fetch_array($customer_address_query);

  $shipping_address_query = tep_db_query("select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . (int)$customer_id . "' and ab.address_book_id = '" . (int)$sendto . "'");
  $shipping_address = tep_db_fetch_array($shipping_address_query);

  $billing_address_query = tep_db_query("select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . (int)$customer_id . "' and ab.address_book_id = '" . (int)$billto . "'");
  $billing_address = tep_db_fetch_array($billing_address_query);

  $tax_address_query = tep_db_query("select ab.entry_country_id, ab.entry_zone_id from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) where ab.customers_id = '" . (int)$customer_id . "' and ab.address_book_id = '" . (int)($this->content_type == 'virtual' ? $billto : $sendto) . "'");
  $tax_address = tep_db_fetch_array($tax_address_query);

  $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
					  'currency' => $currency,
					  'currency_value' => $currencies->currencies[$currency]['value'],
					  'payment_method' => $payment,
					  'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''),
					  'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''),
					  'cc_number' => (isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : ''),
					  'cc_expires' => (isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : ''),
					  'shipping_method' => $shipping['title'],
					  'shipping_cost' => $shipping['cost'],
					  'subtotal' => 0,
					  'tax' => 0,
					  'tax_groups' => array(),
  //kgt - discount coupons
									  'coupon' => (isset($GLOBALS['coupon']) ? $GLOBALS['coupon'] : ''),
									  'applied_discount' => array(),
									  //end kgt - discount coupons					'comments' => (isset($GLOBALS['comments']) ? $GLOBALS['comments'] : ''));

  if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) {
	$this->info['payment_method'] = $GLOBALS[$payment]->title;

	if ( isset($GLOBALS[$payment]->order_status) && is_numeric($GLOBALS[$payment]->order_status) && ($GLOBALS[$payment]->order_status > 0) ) {
	  $this->info['order_status'] = $GLOBALS[$payment]->order_status;
	}
  }

  $this->customer = array('firstname' => $customer_address['customers_firstname'],
						  'lastname' => $customer_address['customers_lastname'],
						  'company' => $customer_address['entry_company'],
						  'street_address' => $customer_address['entry_street_address'],
						  'suburb' => $customer_address['entry_suburb'],
						  'city' => $customer_address['entry_city'],
						  'postcode' => $customer_address['entry_postcode'],
						  'state' => ((tep_not_null($customer_address['entry_state'])) ? $customer_address['entry_state'] : $customer_address['zone_name']),
						  'zone_id' => $customer_address['entry_zone_id'],
						  'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']),
						  'format_id' => $customer_address['address_format_id'],
						  'telephone' => $customer_address['customers_telephone'],
						  'email_address' => $customer_address['customers_email_address']);

  $this->delivery = array('firstname' => $shipping_address['entry_firstname'],
						  'lastname' => $shipping_address['entry_lastname'],
						  'company' => $shipping_address['entry_company'],
						  'street_address' => $shipping_address['entry_street_address'],
						  'suburb' => $shipping_address['entry_suburb'],
						  'city' => $shipping_address['entry_city'],
						  'postcode' => $shipping_address['entry_postcode'],
						  'state' => ((tep_not_null($shipping_address['entry_state'])) ? $shipping_address['entry_state'] : $shipping_address['zone_name']),
						  'zone_id' => $shipping_address['entry_zone_id'],
						  'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']),
						  'country_id' => $shipping_address['entry_country_id'],
						  'format_id' => $shipping_address['address_format_id']);

  $this->billing = array('firstname' => $billing_address['entry_firstname'],
						 'lastname' => $billing_address['entry_lastname'],
						 'company' => $billing_address['entry_company'],
						 'street_address' => $billing_address['entry_street_address'],
						 'suburb' => $billing_address['entry_suburb'],
						 'city' => $billing_address['entry_city'],
						 'postcode' => $billing_address['entry_postcode'],
						 'state' => ((tep_not_null($billing_address['entry_state'])) ? $billing_address['entry_state'] : $billing_address['zone_name']),
						 'zone_id' => $billing_address['entry_zone_id'],
						 'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3']),
						 'country_id' => $billing_address['entry_country_id'],
						 'format_id' => $billing_address['address_format_id']);

  $index = 0;
  $products = $cart->get_products();
  for ($i=0, $n=sizeof($products); $i<$n; $i++) {
	$this->products[$index] = array('qty' => $products[$i]['quantity'],
									'name' => $products[$i]['name'],
									'model' => $products[$i]['model'],
									'tax' => tep_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']),
									'tax_description' => tep_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']),
									'price' => $products[$i]['price'],
									'final_price' => $products[$i]['price'] + $cart->attributes_price($products[$i]['id']),
									'weight' => $products[$i]['weight'],
									'id' => $products[$i]['id']);

	if ($products[$i]['attributes']) {
	  $subindex = 0;
	  reset($products[$i]['attributes']);
	  while (list($option, $value) = each($products[$i]['attributes'])) {
		$attributes_query = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . (int)$products[$i]['id'] . "' and pa.options_id = '" . (int)$option . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int)$value . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . (int)$languages_id . "' and poval.language_id = '" . (int)$languages_id . "'");
		$attributes = tep_db_fetch_array($attributes_query);

		$this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options_name'],
																 'value' => $attributes['products_options_values_name'],
																 'option_id' => $option,
																 'value_id' => $value,
																 'prefix' => $attributes['price_prefix'],
																 'price' => $attributes['options_values_price']);

		$subindex++;
	  }
	}

	//kgt - discount coupon
	if( !empty( $this->info['coupon'] ) ) {
		if( !isset( $this_coupon ) ) {
	require_once( DIR_WS_CLASSES . 'discount_coupon.php' );
		$this_coupon = new discount_coupon( $this->info['coupon'] );
		}
		$applied_discount = $this_coupon->calculate_discount( $this->products[$index], $n );
	  if( isset( $this->info['applied_discount'][$this->products[$index]['tax_description']] ) ) {
	  $this->info['applied_discount'][$this->products[$index]['tax_description']] += $applied_discount;
		} else {
		$this->info['applied_discount'][$this->products[$index]['tax_description']] = $applied_discount;
	}
	$this_actual_shown_price = null;
	if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'false' ) {
		//we don't want to display the subtotal with the discount applied, so apply the discount then set the applied_discount variable to zero so that it's not added into the order subtotal, but is still used to correctly calculate tax
		$this_actual_shown_price = ( tep_add_tax( $this->products[$index]['final_price'], $this->products[$index]['tax'] ) * $this->products[$index]['qty'] ) - $applied_discount;
		$applied_discount = 0;
	}
	}
	$shown_price = ( tep_add_tax( $this->products[$index]['final_price'], $this->products[$index]['tax'] ) * $this->products[$index]['qty'] ) - $applied_discount;
	$this->info['subtotal'] += $shown_price;
	//if we need to display the subtotal without the discount applied, then add the shown price to the subtotal, then change shown price to the price with the applied discount in order to properly calculate taxes
	if( isset( $this_actual_shown_price ) ) $shown_price = $this_actual_shown_price;
	//end kgt - discount coupon
 $products_tax = $this->products[$index]['tax'];
	$products_tax_description = $this->products[$index]['tax_description'];
	if (DISPLAY_PRICE_WITH_TAX == 'true') {
	  $this->info['tax'] += $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)));
	  if (isset($this->info['tax_groups']["$products_tax_description"])) {
		$this->info['tax_groups']["$products_tax_description"] += $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)));
	  } else {
		$this->info['tax_groups']["$products_tax_description"] = $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)));
	  }
	} else {
	  $this->info['tax'] += ($products_tax / 100) * $shown_price;
	  if (isset($this->info['tax_groups']["$products_tax_description"])) {
		$this->info['tax_groups']["$products_tax_description"] += ($products_tax / 100) * $shown_price;
	  } else {
		$this->info['tax_groups']["$products_tax_description"] = ($products_tax / 100) * $shown_price;
	  }
	}

	$index++;
  }

  if (DISPLAY_PRICE_WITH_TAX == 'true') {
	$this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
  } else {
	$this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost']; //kgt - discount coupon
if( !empty( $this->info['coupon'] ) && MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'false' ) {
  foreach( $this->info['applied_discount'] as $discount ){
		$this->info['total'] -= $discount;
	  }
}
//end kgt - discount coupon

  }
}
 }
?>

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

×