Post by nickelaj » Wed Feb 26, 2020 5:00 pm

Hi,
I am using 3.0.2.0 version. Getting "Division by zero in /catalog/controller/product/category.php on line 209Warning: Division by zero in" error. Looked at the line and saw that below is making this because of zero priced products. How can i take it into if else formula ?

Code: Select all

'sprice'       => round(($price-$special)/$price*100),

Code: Select all

$data['products'][] = array(
					'product_id'  => $result['product_id'],
					'thumb'       => $image,
					'thumb_swap'  => $images,
					'name'        => $result['name'],
					'quantity' => $result['quantity'],
					'price'       => $price,
					'special'     => $special,
					'sprice'       => round(($price-$special)/$price*100),
					'tax'         => $tax,
					'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
					'rating'      => $result['rating'],
					'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
				);

New member

Posts

Joined
Fri Mar 27, 2015 7:53 pm

Post by letxobnav » Wed Feb 26, 2020 5:06 pm

then check if the price > 0 before doing a division.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by kestas » Wed Feb 26, 2020 6:17 pm

Before your array add:

Code: Select all

if ($price > 0  && $special) {
    $sprice = round(($price-$special)/$price*100);
} else {
    $sprice = ' ';
}
than in array this :

Code: Select all

'sprice'       =>   round(($price-$special)/$price*100),
change to:

Code: Select all

'sprice'       =>  $sprice,
Better all changes to do using OCMOD
Last edited by kestas on Wed Feb 26, 2020 11:06 pm, edited 1 time in total.

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by nickelaj » Wed Feb 26, 2020 6:18 pm

letxobnav wrote:
Wed Feb 26, 2020 5:06 pm
then check if the price > 0 before doing a division.
I tried but couldn't use if/else statement correctly for checking, than asked for help.

Code: Select all

$data['products'][] = array(
					'product_id'  => $result['product_id'],
					'price'       => $price,
					'special'     => $special,
					$ozzy =  round(($price-$special)/$price*100),
					if ($ozzy   > 0){
                                        'sprice'       => round(($price-$special)/$price*100),
                                                       } else {
                                        // Do something with the zero
                                                                    }
					'tax'         => $tax,
		
					);

New member

Posts

Joined
Fri Mar 27, 2015 7:53 pm

Post by paulfeakins » Wed Feb 26, 2020 6:40 pm

letxobnav wrote:
Wed Feb 26, 2020 5:06 pm
then check if the price > 0 before doing a division.
Haha indeed. Sometimes it's so simple.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by nickelaj » Wed Feb 26, 2020 6:58 pm

kestas wrote:
Wed Feb 26, 2020 6:17 pm
Before your array add:

Code: Select all

if ($price > 0 ) {
    $sprice = round(($price-$special)/$price*100);
} else {
    $sprice = ' ';
}
than in array this :

Code: Select all

'sprice'       =>   round(($price-$special)/$price*100),
change to:

Code: Select all

'sprice'       =>  $sprice,
Better all changes to do using OCMOD
Thanks a lot @kestas for your answer . It worked for me.
Regards

New member

Posts

Joined
Fri Mar 27, 2015 7:53 pm

Post by paulfeakins » Wed Feb 26, 2020 7:25 pm

nickelaj wrote:
Wed Feb 26, 2020 6:58 pm
Thanks a lot @kestas for your answer . It worked for me.
But the algorithm is changed so specials won't work now.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by nickelaj » Wed Feb 26, 2020 7:48 pm

paulfeakins wrote:
Wed Feb 26, 2020 7:25 pm
nickelaj wrote:
Wed Feb 26, 2020 6:58 pm
Thanks a lot @kestas for your answer . It worked for me.
But the algorithm is changed so specials won't work now.
Than please help for make it work. You are only saying it is simple. I think it is simple for you but not for me.

New member

Posts

Joined
Fri Mar 27, 2015 7:53 pm

Post by letxobnav » Wed Feb 26, 2020 8:34 pm

sprice is percentage off right?
looks just fine.

personally I would set $spice = false instead of ' ' so you can conditionally display it with
{% if sprice %}
{{ sprice }} % off
{% endif %}

something like that.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by kestas » Thu Feb 27, 2020 12:00 am

nickelaj wrote:
Wed Feb 26, 2020 7:48 pm
paulfeakins wrote:
Wed Feb 26, 2020 7:25 pm
nickelaj wrote:
Wed Feb 26, 2020 6:58 pm
Thanks a lot @kestas for your answer . It worked for me.
But the algorithm is changed so specials won't work now.
Than please help for make it work. You are only saying it is simple. I think it is simple for you but not for me.
I have edited my first post. So code little bit changed. Statement $special is added.

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by nickelaj » Thu Feb 27, 2020 4:49 pm

kestas wrote:
Thu Feb 27, 2020 12:00 am
nickelaj wrote:
Wed Feb 26, 2020 7:48 pm
paulfeakins wrote:
Wed Feb 26, 2020 7:25 pm

But the algorithm is changed so specials won't work now.
Than please help for make it work. You are only saying it is simple. I think it is simple for you but not for me.
I have edited my first post. So code little bit changed. Statement $special is added.
This is solved for me. I didnt see any problem
Thanks and regards :)

New member

Posts

Joined
Fri Mar 27, 2015 7:53 pm

Post by paulfeakins » Thu Feb 27, 2020 5:59 pm

nickelaj wrote:
Thu Feb 27, 2020 4:49 pm
I didnt see any problem
No, and you won't until you use discounts or specials.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by nickelaj » Thu Feb 27, 2020 8:23 pm

paulfeakins wrote:
Thu Feb 27, 2020 5:59 pm
nickelaj wrote:
Thu Feb 27, 2020 4:49 pm
I didnt see any problem
No, and you won't until you use discounts or specials.
I can't understand what you really want. You are wasting your time to say me i will fail but you dont tell the right solution. Am i asking wrong question or choosing wrong place ?

New member

Posts

Joined
Fri Mar 27, 2015 7:53 pm

Post by paulfeakins » Thu Feb 27, 2020 8:43 pm

nickelaj wrote:
Thu Feb 27, 2020 8:23 pm
I can't understand what you really want. You are wasting your time to say me i will fail but you dont tell the right solution. Am i asking wrong question or choosing wrong place ?
Another developer gave a solution that may cause wrong prices in certain circumstances. I don't have time to code this for you for free but I am saying be careful to test the price comes out correctly.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by kestas » Thu Feb 27, 2020 9:30 pm

paulfeakins wrote:
Thu Feb 27, 2020 8:43 pm
nickelaj wrote:
Thu Feb 27, 2020 8:23 pm
I can't understand what you really want. You are wasting your time to say me i will fail but you dont tell the right solution. Am i asking wrong question or choosing wrong place ?
Another developer gave a solution that may cause wrong prices in certain circumstances. I don't have time to code this for you for free but I am saying be careful to test the price comes out correctly.
@nickelaj Do not pay attention... The code is proper, which is slightly corrected in my first post. I have added condition which should solve the problem for the product which do not have special price. Thank's @paulfeakins
If you will have any problem you can write me PM.

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by letxobnav » Thu Feb 27, 2020 9:37 pm

Another developer gave a solution that may cause wrong prices in certain circumstance
well, that is some disappointing nonsense as there are no prices calculated here.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by nickelaj » Fri Mar 13, 2020 1:22 am

kestas wrote:
Thu Feb 27, 2020 9:30 pm
paulfeakins wrote:
Thu Feb 27, 2020 8:43 pm
nickelaj wrote:
Thu Feb 27, 2020 8:23 pm
I can't understand what you really want. You are wasting your time to say me i will fail but you dont tell the right solution. Am i asking wrong question or choosing wrong place ?
Another developer gave a solution that may cause wrong prices in certain circumstances. I don't have time to code this for you for free but I am saying be careful to test the price comes out correctly.
@nickelaj Do not pay attention... The code is proper, which is slightly corrected in my first post. I have added condition which should solve the problem for the product which do not have special price. Thank's @paulfeakins
If you will have any problem you can write me PM.
Thanks a lot

New member

Posts

Joined
Fri Mar 27, 2015 7:53 pm
Who is online

Users browsing this forum: No registered users and 30 guests