Jump to content
kgt

[Contribution] Discount Coupon Codes

Recommended Posts

Hi all,

 

Has anyone come up with this sort of bug as well?...

 

Sort order: discount before the subtotal

Display subtotal with applied discount?: true

Everything else default

 

and if any one product in my cart has a quantity of more than 1 the total amount is always wrong...

 

I got everything to work right using these setting but would like to use the above settings:

 

Sort order: subtotal before the discount

Display subtotal with applied discount?: false

Everything else default

 

I would appreciate any feedback,

Thanks in advance,

a8le

 

I believe I have this fixed. Please send me a PM or an email with your email address and I will send you updated files to try. If they work for you, I'll release them as soon as I get upgrade instructions done.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Anyone know what the lines in red do below? This coupon contribution only works if i delete these lines. If i don't i get a shipping error every time i try to check out.

catalog/checkout_confirmation.php, you are supposed to add

 

//kgt - discount coupons

if( tep_not_null( $coupon ) && is_object( $order->coupon ) ) { //if they have entered something in the coupon field

$order->coupon->verify_code();

if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DEBUG != 'true' ) {

if( !$order->coupon->is_errors() ) { //if we have passed all tests (no error message), make sure we still meet free shipping requirements, if any

if( $order->coupon->is_recalc_shipping() ) tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( ENTRY_DISCOUNT_COUPON_SHIPPING_CALC_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( ' ', $order->coupon->get_messages() ) ), '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') ) { //we had a coupon entered before, so we need to unregister it

tep_session_unregister('coupon');

//now check to see if we need to recalculate shipping:

require_once( DIR_WS_CLASSES.'discount_coupon.php' );

if( discount_coupon::is_recalc_shipping() ) tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( ENTRY_DISCOUNT_COUPON_SHIPPING_CALC_ERROR ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method}

}

//end kgt - discount coupons

 

Those lines are used to determine if shipping needs to be recalculated due to the discount being applied. If you don't care about that, then you can leave them commented out to no detriment. If you want to check ship rates, I'll need more information, such as the shipping module you're using, whether you allow free shipping, etc.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Thanks for the quick response. Yes, it does have a unique sort order. Should've specified that before. I can't imagine it being something complicated seeing as how everything installed perfect with no error codes. Am i missing something here?

 

 

The next most common reason it doesn't show up is because you've missed installing some code in includes/classes/order.php. Double check the install for that file. If that one is fine, next most common is missing the changes to checkout_confirmation.php.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
I'm still struggling with this update of the coupons...

I dont have the discount calculated in the total

 

Sub-Total: 5.00EUR

Shipping with TNT Dutch Post (Normal Shipping): 1.35EUR

Discount Coupon testTG 20.00EUR applied: -20.00EUR

Total: 6.35EUR

 

where is this calculated?

 

Cheers

 

 

You can apply the discount directly to the subtotal (or not) depending on your configuration setting in Modules > Order Total > Discount Coupon. Please see the manual for information on how to configure DCC.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
I never noticed the multiple discounts before either as I only use it for a discounted shipping, but I think I it's due to the fact that the discount is taken before the sub-total no matter where you place the sub-total or discount in the Orders Total module. It should actually be taken from the sub-total and that wouldn't happen.

 

I use CCGV(TRAD) along with this contrib. The CCGV takes it from the sub-total as it should if you place it after the sub-total in the sort order. I'm using the shipping option for the Coupons so it deducts for the shipping just fine, but it then removes that amount from the sub-total. Even if you use the option not to show it deducted from the sub-total it is.

 

1 - Item = 10.00

Sub-total= 10

10% discount = -0.95 CCGV(TRAD)

Shipping: 5.00

10% Shipping Discount: -0.50 (Discount coupons)

Total= 13.55

 

Above is an example of what this contrib is doing.

The discount for CCGV should be 1.00 not .95

The shipping discount is being subtracted from the sub-total.

 

I think this is how it's coded and not a bug. The multiple discounts is probably, but I think that is a result of it being forced to take before the sub-total and not from the sub-total. If taken from the sub-total it would benefit the customer which is what a coupon is for.

 

Just my two cents.

 

 

I'm sorry, I don't see what you mean by the shipping discount being applied to the subtotal. In fact the entire calculation above looks perfect to me. If the CCGV discount is off, that's because CCGV is using the shipping discount in some way. Shipping discounts aren't applied to the subtotal.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
I'm having the same problem too. Others must be running into this problem also or don't know it exists until they've added multiple items and apply a percentage discount.

 

4 x whatever = 16.00

___________________

Sub-Total: $6.40

Discount Coupon OT15OFF applied: -$2.40

Table Rate (Best Way): $2.50

CA TAX 8.70%: $0.56

Total: $9.46

 

The coupon is only for 15% off...but like the others said, its muliplying the 15% of ALL to each item.

 

 

If you send me a PM or email with your email address, I will send you the updated files that should fix this. If it fixes your problem, I'll package them up.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
I installed the mod and it appears to be working correctly. I created a coupon for $5 off. My only problem is that it is applying the $5 off to each item, rather than the order total. Did I create the coupon incorrectly, or do I need to make a programming change somewhere?

 

 

Can you send me a debug output for this? Instructions on how to get the debug output are in the manual.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
One last thing that may help out. I did install a contribution that figures out the shipping rate based on a percentage of the sale. This maybe what is causing the shipping error. Please let me know if any way to use the the percentage based shipping and the coupon contribution. The shipping percentage conrtibution can be found at http://www.oscommerce.com/community/contri...arch,percentage

 

 

Yes, that is probably causing the problem. If you don't need shipping to be re-checked when the customer uses a discount, then leave the lines commented out.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
KGT,

 

Were you ever able to look into this? I would be interested as well.

 

Thanks!

 

 

It depends on the paypal module. It would be a simple change. All you would need to do is edit the payment module. I can give generic instructions for doing so. I haven't tested this, so please make these changes on a test site.

 

includes/modules/payment/paypal_whatever.php (whatever the name of your paypal module is)

 

find:

function before_process() {

 

if it doesn't look like this:

	function before_process() {
  return false;
}

Then add this code right after the "function before_process() {" part:

function before_process() {
global $order;
if($order->info['total'] != 0) {

 

and before the closing } for that function, add another }.

 

Do the same to after_process if it's not empty. So your function(s) might look like this:

 

	function before_process() {
  global $order;
  if($order->info['total'] != 0) {
	//existing paypal code in this function
  }
}

function after_process() {
  global $order;
  if($order->info['total'] != 0) {
	//existing paypal code in this function
  }
}


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
The next most common reason it doesn't show up is because you've missed installing some code in includes/classes/order.php. Double check the install for that file. If that one is fine, next most common is missing the changes to checkout_confirmation.php.

 

Ok, it was missing code in order.php, thanks!!! But now I am getting a -Total when its set to false. Also the Sub-total is all out of wack. For example:

 

I used a coupon that gives 75% off. (entered as .75) The total for the order is $1,300.00 However the Subtotal says, $-96,200.00, The Total $0.00 and the Applied Coupon $-975.00.

 

Any ideas? Thanks again!

Share this post


Link to post
Share on other sites

First off, this is a great contribution! It installed easily and everything seems to be working well, except for one small thing - the shipping zone exclusions. I set up a special discount that is intended for CA residents (to help off set sales tax), but it appears to be working for everyone. Any ideas? Thanks.

 

Bruce

Share this post


Link to post
Share on other sites
Ok, it was missing code in order.php, thanks!!! But now I am getting a -Total when its set to false. Also the Sub-total is all out of wack. For example:

 

I used a coupon that gives 75% off. (entered as .75) The total for the order is $1,300.00 However the Subtotal says, $-96,200.00, The Total $0.00 and the Applied Coupon $-975.00.

 

Any ideas? Thanks again!

 

 

I just uploaded a bugfix for subtotals. See if that fixes your subtotal problem.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
First off, this is a great contribution! It installed easily and everything seems to be working well, except for one small thing - the shipping zone exclusions. I set up a special discount that is intended for CA residents (to help off set sales tax), but it appears to be working for everyone. Any ideas? Thanks.

 

Bruce

 

 

Can you PM or email me some debug output for this? Make sure you use a CA shipping address when you checkout. See the manual for help on getting debug output.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
It does indeed take discounts before the subtotal and not from it. That point is made in the documentation for this contribution and several times in this very thread. The reason why has to do with how osCommerce calculates tax. You can't just take the discount from the subtotal. This would fail miserably for store owners who have multiple tax groups (think non-taxable products and taxable products in the same cart).

 

I'm not sure what you're talking about in regards to the shipping discount. I can't seem to duplicate a shipping discount being applied to the subtotal.

 

Ok I understand the reasoning then behind taking it first. I don't deal with non-taxable and taxable in the same cart it's either all or none. I can see where that would cause problems. Thanks for clearing that up.

 

So i'm guessing that shipping discounts are not supposed to be involved with the sub-total then? I have the CCGV and Cusomter loyalty discount installed in the test store along with this contrib and I can get the other two to work as they should with the right figures if I don't use the shipping discount. As soon as I introduce the shipping discount it throws the others off by as much as the shipping discount when appplied to the sub-total. It doesn't seem to matter where I place the other contribs at in the sort order, it's always off.

 

3 x Violet Lime Scented Tart $1.50

 

Sub-Total: $1.50

Customer Loyalty Discount:

You have spent $292.80 in the last year so qualify for a discount of 7.5%: $0.08

United States Postal Service (1 x 1.15lbs) (Priority (2 - 3 Days)): $4.60

Discount 56VUFY for 10% off shipping applied.: -$0.46

WV TAX 6.0%: $0.08

Total: $5.65

 

Another exmaple posted above. But notice the Loyality discount is off.

If you subtract the shipping disount from the item sub-total and then apply then apply the 7.5% it gives you the .08 discount. CCGV is doing the same thing. if I don't apply the shipping discount, then the figures come out correctly based on order total sort.

 

So if the shipping is not applied to the sub-total then I guess I need to figureout how it's getting added to the sub-total when either of the other two contribs are used with this one.


Currently running 76 contibutions.

Share this post


Link to post
Share on other sites

Discount Coupon Codes version 3.3 has been uploaded

 

Bug Fixes:

  • Fixed bug that caused subtotal to be incorrect when products with more than 1 quantity are in cart.

This is a full package. Upgrade instructions assume version 3.2 is installed.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
Ok I understand the reasoning then behind taking it first. I don't deal with non-taxable and taxable in the same cart it's either all or none. I can see where that would cause problems. Thanks for clearing that up.

 

So i'm guessing that shipping discounts are not supposed to be involved with the sub-total then? I have the CCGV and Cusomter loyalty discount installed in the test store along with this contrib and I can get the other two to work as they should with the right figures if I don't use the shipping discount. As soon as I introduce the shipping discount it throws the others off by as much as the shipping discount when appplied to the sub-total. It doesn't seem to matter where I place the other contribs at in the sort order, it's always off.

 

3 x Violet Lime Scented Tart $1.50

 

Sub-Total: $1.50

Customer Loyalty Discount:

You have spent $292.80 in the last year so qualify for a discount of 7.5%: $0.08

United States Postal Service (1 x 1.15lbs) (Priority (2 - 3 Days)): $4.60

Discount 56VUFY for 10% off shipping applied.: -$0.46

WV TAX 6.0%: $0.08

Total: $5.65

 

Another exmaple posted above. But notice the Loyality discount is off.

If you subtract the shipping disount from the item sub-total and then apply then apply the 7.5% it gives you the .08 discount. CCGV is doing the same thing. if I don't apply the shipping discount, then the figures come out correctly based on order total sort.

 

So if the shipping is not applied to the sub-total then I guess I need to figureout how it's getting added to the sub-total when either of the other two contribs are used with this one.

 

 

My guess is that the root of the problem is due to a conflict between how DCC and CCGV work. CCGV and DCC apply discounts at different points in the process, which is one of the reasons I developed DCC. I had a customer with taxable and non-taxable items and needed a discount to be applied to each item. CCGV, as I last looked at it, applies discounts to the subtotal. That works fine, and is more accurate for many people, especially if you tend to have carts with large numbers of items. Depending on how it's configured, CCGV will completely recalculate all order totals if it's set to do so. Check that module setting first, and see if toggling that makes a difference.

 

I suspect the cause is thus:

 

DCC applies the discount in the order class (includes/classes/order.php)

CCGV applies the discount in the order total module

 

DCC happens before CCGV.

 

CCGV pulls the order total from the order class (which has the DCC discount applied) and recalculates tax and shipping and subtracts the CCGV discount. So CCGV is seeing the shipping discount already applied, and just integrating that discount into the subtotal.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
My guess is that the root of the problem is due to a conflict between how DCC and CCGV work. CCGV and DCC apply discounts at different points in the process, which is one of the reasons I developed DCC. I had a customer with taxable and non-taxable items and needed a discount to be applied to each item. CCGV, as I last looked at it, applies discounts to the subtotal. That works fine, and is more accurate for many people, especially if you tend to have carts with large numbers of items. Depending on how it's configured, CCGV will completely recalculate all order totals if it's set to do so. Check that module setting first, and see if toggling that makes a difference.

 

I suspect the cause is thus:

 

DCC applies the discount in the order class (includes/classes/order.php)

CCGV applies the discount in the order total module

 

DCC happens before CCGV.

 

CCGV pulls the order total from the order class (which has the DCC discount applied) and recalculates tax and shipping and subtracts the CCGV discount. So CCGV is seeing the shipping discount already applied, and just integrating that discount into the subtotal.

 

 

This might fix it:

 

includes/classes/order.php

 

replace this:

	  //kgt - discount coupon
  if( is_object( $this->coupon ) ) {
	$this->info['total'] = $this->coupon->finalize_discount( $this->info );
  }
  //end kgt - discount coupon

 

with this:

	  //kgt - discount coupon
  if( is_object( $this->coupon ) ) {
	$this->info['total'] = $this->coupon->finalize_discount( $this->info );
	if( $this->coupon->coupon['coupons_discount_type'] == 'shipping' ) $this->info['shipping_cost'] = $this->coupon->applied_discount['shipping'];
  }
  //end kgt - discount coupon

 

CCGV might still try to integrate the discount into the subtotal, in which case you'll need to add:

 

if( $this->coupon->coupon['coupons_discount_type'] != 'shipping' )

 

right before the

 

$this->info['total'] = $this->coupon->finalize_discount( $this->info );

 

line.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
My guess is that the root of the problem is due to a conflict between how DCC and CCGV work. CCGV and DCC apply discounts at different points in the process, which is one of the reasons I developed DCC. I had a customer with taxable and non-taxable items and needed a discount to be applied to each item. CCGV, as I last looked at it, applies discounts to the subtotal. That works fine, and is more accurate for many people, especially if you tend to have carts with large numbers of items. Depending on how it's configured, CCGV will completely recalculate all order totals if it's set to do so. Check that module setting first, and see if toggling that makes a difference.

 

I suspect the cause is thus:

 

DCC applies the discount in the order class (includes/classes/order.php)

CCGV applies the discount in the order total module

 

DCC happens before CCGV.

 

CCGV pulls the order total from the order class (which has the DCC discount applied) and recalculates tax and shipping and subtracts the CCGV discount. So CCGV is seeing the shipping discount already applied, and just integrating that discount into the subtotal.

 

Just has a look and your 100% spot on. That is exactly what is happening. So these are all working just how they were written. I will play with the settings in the CCGV, but I don't think it will make a difference. It's back to the drawing board for me :'(

 

Thanks for the explanation and update to the contrib!


Currently running 76 contibutions.

Share this post


Link to post
Share on other sites
Just has a look and your 100% spot on. That is exactly what is happening. So these are all working just how they were written. I will play with the settings in the CCGV, but I don't think it will make a difference. It's back to the drawing board for me :'(

 

Thanks for the explanation and update to the contrib!

 

 

That's part of the difficulty with using any discounting scheme with osCommerce. It simply was not written with discounts in mind. So the contributions that apply discounts have to perform some twisted logic to get them to work. It also tends to interfere with other contributions that affect that part of the process. There's just no way around it, unfortunately. Discounts are actually a complicated beast in any cart/checkout software.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites
This might fix it:

 

includes/classes/order.php

 

replace this:

	  //kgt - discount coupon
  if( is_object( $this->coupon ) ) {
	$this->info['total'] = $this->coupon->finalize_discount( $this->info );
  }
  //end kgt - discount coupon

 

with this:

	  //kgt - discount coupon
  if( is_object( $this->coupon ) ) {
	$this->info['total'] = $this->coupon->finalize_discount( $this->info );
	if( $this->coupon->coupon['coupons_discount_type'] == 'shipping' ) $this->info['shipping_cost'] = $this->coupon->applied_discount['shipping'];
  }
  //end kgt - discount coupon

 

CCGV might still try to integrate the discount into the subtotal, in which case you'll need to add:

 

if( $this->coupon->coupon['coupons_discount_type'] != 'shipping' )

 

right before the

 

$this->info['total'] = $this->coupon->finalize_discount( $this->info );

 

line.

thanks for the code to try. It gave me some strange discount totals and I couldn't figure out what it was doing...lol Do appreciate you taking the time to try and give me a fix. I'm going on with plan B for shipping. Just going to have to do this the hard way...lol.

 

Thanks again for the help.


Currently running 76 contibutions.

Share this post


Link to post
Share on other sites

Hi,

 

coupon works perfect but after an sql optimize i get the following error.

i have installed de DB again but nothing helpt. The tables are all there.

 

1146 - Table '**********_test.TABLE_DISCOUNT_COUPONS' doesn't exist

 

SELECT dc.* FROM TABLE_DISCOUNT_COUPONS dc WHERE coupons_id = 'test' AND ( coupons_date_start <= CURDATE() OR coupons_date_start IS NULL ) AND ( coupons_date_end >= CURDATE() OR coupons_date_end IS NULL )

 

[TEP STOP]

 

someone a solution?

 

thanks,

Jan

Edited by jan64

Dreams can come true, if you help them a littlebit

Share this post


Link to post
Share on other sites
Hi,

 

coupon works perfect but after an sql optimize i get the following error.

i have installed de DB again but nothing helpt. The tables are all there.

 

1146 - Table '**********_test.TABLE_DISCOUNT_COUPONS' doesn't exist

 

SELECT dc.* FROM TABLE_DISCOUNT_COUPONS dc WHERE coupons_id = 'test' AND ( coupons_date_start <= CURDATE() OR coupons_date_start IS NULL ) AND ( coupons_date_end >= CURDATE() OR coupons_date_end IS NULL )

 

[TEP STOP]

 

someone a solution?

 

thanks,

Jan

 

 

Please revisit the install instructions, specifically the section on editing includes/database_tables.php.


Contributions

 

Discount Coupon Codes

Donations

Share this post


Link to post
Share on other sites

Thanks for your reaction.

 

i thought i had it all, but i take a look.

 

Regards,

jan


Dreams can come true, if you help them a littlebit

Share this post


Link to post
Share on other sites
Thanks for your reaction.

 

i thought i had it all, but i take a look.

 

Regards,

jan

 

 

Verry strange, it looks if someone had restored an old backup.

you were right, the files were not edit.

 

Thanks!!


Dreams can come true, if you help them a littlebit

Share this post


Link to post
Share on other sites
Bug Fixes:
  • Fixed bug that caused subtotal to be incorrect when products with more than 1 quantity are in cart.

 

Hi KGT,

 

Thanks for the very cool module. I'm having a similar problem to the other people over the past few posts, where my order total is incorrect. In my case, it's not just happening when I have multiple items in the cart, though. It happens with only one item, as well.

 

I downloaded the package yesterday, but I believe I downloaded it after you had already applied the bug fix. When I compare the file timestamps and sizes in the current package and those in the one I installed, the only differences I see are in the timestamps on the folder creation.

 

Can you let me know which files changed in the bugfix so I can compare them against the files I have installed, rather than going through the whole installation procedure again?

 

Thanks,

Stace


The soul is greater than the hum of its parts. -- Douglas R. Hofstadter in Gödel, Escher, Bach

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

×