Forums / Bug Reports / [Done v2.0.0] Divide by Zero error with ot_coupon.php

[Done v2.0.0] Divide by Zero error with ot_coupon.php

Locked

Views: 9,178

Results 1 to 19 of 19
This thread is locked. New replies are disabled.
13 Apr 2008, 5:45 AM
#1
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

[Done v2.0.0] Divide by Zero error with ot_coupon.php

I have read the thread at http://www.zen-cart.com/forum/showthread.php?t=82619&highlight=ot_group_pricing
And DrByte's post #10

Seeing this type of error during checkout when applying a coupon and getting:

Warning: Division by zero in /includes/modules/order_total/ot_coupon.php on line 365
Code at 365

$ratioTax = $adjustedTax/$order->info['tax'];

Any insight as to where in this file would a correction be applied and what would it be?

Zen-Venom Get Bitten

13 Apr 2008, 11:59 AM
#2
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,720
Plugin Contributions:
56

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

I could have sworn I posted this fix, but of course I can't find it now.

If you just move this line down into the foreach loop, you'll be fine.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

13 Apr 2008, 11:20 PM
#3
jonathank avatar

jonathank

New Zenner

Join Date:
Apr 2008
Posts:
3
Plugin Contributions:
0

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

Hi,

I have the same issue with kobra. It gives me the following when I applied the discount code at the order confirmation page.

public_html/includes/modules/order_total/ot_coupon.php on line 364

$ratioTax = $adjustedTax/$order->info['tax'];

The checkout still works (at least till at paypal page which I stopped at) but it has affected some parts of the site layout at that page.

swguy, apologies about this but what do you mean "move this line down into the foreach loop"?

Hope to get this rectify soon as my customers will use the coupon soon. Thanks!

14 Apr 2008, 4:03 AM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

I have the same issue with kobra. It gives me the following when I applied the discount code at the order confirmation page.
I actually went back to a demo install that I have and this has only default files and this works there without a hitch.

I am off to check my overrides files

Zen-Venom Get Bitten

14 Apr 2008, 5:56 PM
#5
jonathank avatar

jonathank

New Zenner

Join Date:
Apr 2008
Posts:
3
Plugin Contributions:
0

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

kobra:

I actually went back to a demo install that I have and this has only default files and this works there without a hitch.

I am off to check my overrides files
Keep us updated kobra. :)

My site currently running on Zen Cart 1.3.8a.

Normal checkout processing works fine without a hitch. It's only when coupon code is applied then the error appeared and it screws up the layout as well. Be it for individual or for group usage. Fortunately, it allows checkout to the payment page still. I found out the bug only when I did a test myself with a valid coupon code.

14 Apr 2008, 6:19 PM
#6
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

Keep us updated
When I switced to the classic template I did not have the issue and so knew this had to do with some overridden template file - If you are using overrides religiously you can try the same thing

And/or list the Module additions you have

Zen-Venom Get Bitten

14 Apr 2008, 6:35 PM
#7
jonathank avatar

jonathank

New Zenner

Join Date:
Apr 2008
Posts:
3
Plugin Contributions:
0

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

kobra:

When I switced to the classic template I did not have the issue and so knew this had to do with some overridden template file - If you are using overrides religiously you can try the same thing
Yes, my site using overrides.
When you say to try the same thing, do you mean swguy's remedy? He mentioned "If you just move this line down into the foreach loop" What does that mean in layman terms?

kobra:

And/or list the Module additions you have
These are the modules installed. Some remain unused.

Order Total Modules:
Discount Coupon*
Group Discount (unused)
Gift Certificates (unused)
Low Order Fee (unused)
Shipping
Sub-Total
Tax (Installed but I don't include tax at all)
Total

*This module is installed
true

Sort Order
280

Include Shipping
false

Include Tax
false

Re-calculate Tax
Standard

Tax Class
--none--

Shipping Modules
Flat Rate
Zone Rates

Payment Modules
PayPal IPN - Website Payments Standard

14 Apr 2008, 9:02 PM
#8
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

When you say to try the same thing, do you mean swguy's remedy?
No, I meant switching to the classic template to see if this corrects it as it did for me - indicating that some override file was the culprit

Zen-Venom Get Bitten

30 Apr 2008, 7:17 AM
#9
reden avatar

reden

New Zenner

Join Date:
Dec 2007
Posts:
23
Plugin Contributions:
0

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

swguy:

I could have sworn I posted this fix, but of course I can't find it now.

If you just move this line down into the foreach loop, you'll be fine.

Thanks, this fixed it for me.

24 Jun 2008, 3:18 PM
#10
blessisaacola avatar

blessisaacola

Totally Zenned

Join Date:
Feb 2004
Location:
Georgia, USA
Posts:
1,875
Plugin Contributions:
1

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

reden:

Thanks, this fixed it for me.

Would someone please kindly post the actual fix and how it should be implemented?

Thanks!

25 Jun 2008, 1:38 AM
#11
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,720
Plugin Contributions:
56

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

Change this

            $ratioTax = $adjustedTax/$order->info['tax'];

to this

            if (isset($order->info['tax']) && ($order->info['tax'] != 0)) { 
                 $ratioTax = $adjustedTax/$order->info['tax'];
             } else { 
                $ratioTax = 0; 
             }

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

8 Feb 2009, 4:37 PM
#12
bigben6 avatar

bigben6

New Zenner

Join Date:
Feb 2009
Posts:
2
Plugin Contributions:
0

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

Thanks swguy. New Zen Cart user here. I was having the same problem and I tried your recommendation of simply replacing...

             $ratioTax = $adjustedTax/$order->info['tax'];

with...

        if (isset($order->info['tax']) && ($order->info['tax'] != 0)) { 
             $ratioTax = $adjustedTax/$order->info['tax'];
         } else { 
            $ratioTax = 0; 
         }

on ot_coupon.php

But that causes a whole new issue and gives me the following error...

Parse error: syntax error, unexpected T_CLASS in /home2/teddecom/public_html/store/includes/modules/order_total/ot_coupon.php on line 1

What have I missed?

8 Feb 2009, 5:31 PM
#13
bigben6 avatar

bigben6

New Zenner

Join Date:
Feb 2009
Posts:
2
Plugin Contributions:
0

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

Ah Ha! Presto. Got it to work just as you said. Struggled for hours then right after I posted this I realized there was something screwy happening with my text editor when saving my new ot_coupon.php. Fixed that issue and now your fix works like a champ!

8 Feb 2009, 5:40 PM
#14
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,720
Plugin Contributions:
56

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

Glad to hear it worked out for you.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

18 Mar 2009, 7:57 PM
#15
fuzziest avatar

fuzziest

New Zenner

Join Date:
Jan 2009
Posts:
12
Plugin Contributions:
0

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

Thanks guys, I had the same problem and the above code worked perfectly.

3 Apr 2009, 1:50 AM
#16
shocker avatar

shocker

Zen Follower

Join Date:
Jul 2007
Location:
Jakarta
Posts:
346
Plugin Contributions:
0

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

swguy:

Change this

        $ratioTax = $adjustedTax/$order->info['tax'];
> 
> 
> ```
            if (isset($order->info['tax']) && ($order->info['tax'] != 0)) { 
                 $ratioTax = $adjustedTax/$order->info['tax'];
             } else { 
                $ratioTax = 0; 
             }

Can I create an override file under modules/order_total/MYTEMPLATE/ot_coupon.php ?

3 Apr 2009, 2:10 AM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

shocker:

Can I create an override file under modules/order_total/MYTEMPLATE/ot_coupon.php ?
Sorry, no. You'll need to edit the original file directly.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

16 May 2009, 6:53 PM
#18
chuckienorton avatar

chuckienorton

New Zenner

Join Date:
Dec 2007
Posts:
54
Plugin Contributions:
0

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

Thanks for the update!!! I wish I had seen this sooner, we launched a big coupon newsletter, and I forgot to test it myself. DANG!

Anyway, glad it was an easy fix.

23 Sep 2010, 6:50 AM
#19
tianya avatar

tianya

New Zenner

Join Date:
Sep 2010
Posts:
4
Plugin Contributions:
0

Re: [Done v2.0.0] Divide by Zero error with ot_coupon.php

I have tried all the methods above ,but failed .the warning still show up .Who has else better solution ,Thanks