VirtueMart Forum

VirtueMart 2 + 3 + 4 => Installation, Migration & Upgrade => Topic started by: inopia on July 02, 2012, 13:42:56 PM

Title: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: inopia on July 02, 2012, 13:42:56 PM
Hi dudes,

I´ve recently upgrade tu 2.0.8a version. Aparently everything runs ok but system show this warning:

Warning: Division by zero in */administrator/components/com_virtuemart/models/product.php on line 516

How can i do to fix this? It´s a bug from last version 2.0.8a?

Thank you.
Title: Re: Division by Zero on com_virtuemart/models/product.php
Post by: inopia on July 02, 2012, 13:57:06 PM
I´ve observed if select 6 items per page or more this warning dissapears and when i select again 3 items per page all works but if you reloads the site with clean cache this issue appears again.

The warning appears when this line are evaluated:

$rest = $suglimit%$category->products_per_row;

I think $suglimit gets my item limit per row from my VirtueMart settings (10). by the way a division by zero isn´t possible but...

Suggestions?

Thxu

Title: Re: Division by Zero on com_virtuemart/models/product.php
Post by: bytelord on July 02, 2012, 14:19:33 PM
Have the same issue with v2.0.8a.

As i see the $category->products_per_row does not return the products per row, but zero, for that reason that error appears.

Its a bug i suppose that need to get fixed.

Nikos
Title: Re: Division by Zero on com_virtuemart/models/product.php
Post by: bytelord on July 02, 2012, 14:41:54 PM
i find out what have been changed.

the $category->products_per_row is coming from the category configuration on the backend. So by default that value is '0'.
That means that category oprions from shop->configuration are overided from category products_per_row.

If you go to each category and place there an option for products per row then the error is resolved.
Title: Re: Division by Zero on com_virtuemart/models/product.php
Post by: inopia on July 02, 2012, 15:55:48 PM
bytelord, you´re right!

I´ve solved it like you said. I´m a beginner on VM and i don´t think could be this possibility.

If you need something i will try to help you.

Thank you very much.
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: bytelord on July 02, 2012, 16:08:12 PM
You are welcome. Its a bug as i have seen until now, except if there is something wrong with the upgrade from 2.06 to 2.0.8a.

Until now what i have seen is that the "Default number of products in a row" under Configuration->Templates->Shopfront settings is been overrided from the category configuration.
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: inopia on July 02, 2012, 16:37:24 PM
"It's not a bug; it's an undocumented feature!" LOL
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: vynette on July 02, 2012, 17:47:59 PM
Thank you so much Bytelord. I have only just started building my site a few days ago for the first time. I thought I did something wrong. I have changed my 42 categories now and all is good thank you. When they upgrade again next time do they fix that ? And then will the configuration/template numbers over ride those ones I just changed  if I want to change them or will I have to go back  in and change all of them all again ? thank you for your help.
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: inopia on July 02, 2012, 19:18:56 PM
Seriously.

Probably we must set up all the fields correctly and probably the devs must handle default field values when users generated categories, yet users have to know that zero elements in a row have no sense.
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: esanchez1091 on July 02, 2012, 20:04:10 PM
Thanks bytelord that was the fix.....


bytelord

    Beginner
    *
    Posts: 6
        View Profile
        Personal Message (Online)

Re: Division by Zero on com_virtuemart/models/product.php
« Reply #3 on: Today at 06:41:54 »

    Quote

i find out what have been changed.

the $category->products_per_row is coming from the category configuration on the backend. So by default that value is '0'.
That means that category oprions from shop->configuration are overided from category products_per_row.

If you go to each category and place there an option for products per row then the error is resolved.


[attachment cleanup by admin]
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: Milbo on July 02, 2012, 22:47:18 PM
It should be even enough to write this into the vm config. But I checked the code again and found that I am not checking for this, please use this code

if(empty($limit)){
if(!empty($category->limit_list_initial)){
$suglimit = $category->limit_list_initial;
} else {
if(empty($category->limit_list_step)){
$suglimit = VmConfig::get ('list_limit', 20);
} else {
$suglimit = $category->limit_list_step;
}
}
if(empty($category->products_per_row)){
$category->products_per_row = VmConfig::get ('products_per_row', 3);
}
$rest = $suglimit%$category->products_per_row;
$limit = $suglimit - $rest;

}

Then it should work always and use the standard value.
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: bytelord on July 02, 2012, 23:12:29 PM
Thank you for the code snippet.
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: inopia on July 03, 2012, 09:40:04 AM
Thank you for the code.
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: cecilia2330 on July 03, 2012, 18:47:49 PM
Quote from: Milbo on July 02, 2012, 22:47:18 PM
It should be even enough to write this into the vm config. But I checked the code again and found that I am not checking for this, please use this code

if(empty($limit)){
if(!empty($category->limit_list_initial)){
$suglimit = $category->limit_list_initial;
} else {
if(empty($category->limit_list_step)){
$suglimit = VmConfig::get ('list_limit', 20);
} else {
$suglimit = $category->limit_list_step;
}
}
if(empty($category->products_per_row)){
$category->products_per_row = VmConfig::get ('products_per_row', 3);
}
$rest = $suglimit%$category->products_per_row;
$limit = $suglimit - $rest;

}

Then it should work always and use the standard value.

Sorry that, anyone know where to find the vm config. ??
I want to try Milbo 's solution
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: Loris on July 03, 2012, 19:09:57 PM
Quote from: cecilia2330 on July 03, 2012, 18:47:49 PM
Quote from: Milbo on July 02, 2012, 22:47:18 PM
It should be even enough to write this into the vm config. But I checked the code again and found that I am not checking for this, please use this code

if(empty($limit)){
if(!empty($category->limit_list_initial)){
$suglimit = $category->limit_list_initial;
} else {
if(empty($category->limit_list_step)){
$suglimit = VmConfig::get ('list_limit', 20);
} else {
$suglimit = $category->limit_list_step;
}
}
if(empty($category->products_per_row)){
$category->products_per_row = VmConfig::get ('products_per_row', 3);
}
$rest = $suglimit%$category->products_per_row;
$limit = $suglimit - $rest;

}

Then it should work always and use the standard value.

Sorry that, anyone know where to find the vm config. ??
I want to try Milbo 's solution

in /administrator/components/com_virtuemart/models/product.php

replace the original 2.0.8a code if(empty($limit)){
if(!empty($category->limit_list_initial)){
$suglimit = $category->limit_list_initial;
} else {
if(empty($category->limit_list_step)){
$suglimit = VmConfig::get ('list_limit', 20);
} else {
$suglimit = $category->limit_list_step;
}
}

$rest = $suglimit%$category->products_per_row;
$limit = $suglimit - $rest;

}


with the Milbo's code
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: bytelord on July 03, 2012, 21:14:25 PM
The issue has been resolved to version 2.0.8b. So there is no need to change that lines.
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: CreativeDesigns on July 04, 2012, 15:40:48 PM
I had the same problem with the error "/administrator/components/com_virtuemart/models/product.php on line 516"

I went into my category and changed the number of products per line to 5, and when I refreshed my homepage, no products are showing? Why is this happening?
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: cecilia2330 on July 05, 2012, 17:42:06 PM
Thanks!
I update to v.2.0.8b.
It dont have any error message on the webpage
But when I click " next" button , it cant show next page , still the same (first page)
Why will have this problem???
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: cecilia2330 on July 05, 2012, 18:47:43 PM
I update to V 2.0.8c , but the problem still cant solved
While I click "sort by" items (such as change sort by product id to product description) , than click next button , it work perfect

Is it a bug?
I try many time but the problem still exist....
anyone can help me
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: BaidareW on July 05, 2012, 21:46:55 PM
In 2.0.8c products per category view not working as expected. Showing 8 instead of XX.
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: cecilia2330 on July 06, 2012, 17:40:12 PM
Quote from: BaidareW on July 05, 2012, 21:46:55 PM
In 2.0.8c products per category view not working as expected. Showing 8 instead of XX.
sorry BaidareW..can you explain more detail???
Is it mean I cant fix this problem?
But I work fine when I use 2.06 version
Can I downgrade to 2.06......?
Title: Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
Post by: cecilia2330 on July 06, 2012, 17:45:19 PM
I find that when I click next button , it show the link " http://www.premiumyd.com/main/index.php/zh/2012-05-20-17-25-24/travel?start=12 "

If i change the "sort by " button , when I click next button , it shows the link "
http://www.premiumyd.com/main/index.php/zh/2012-05-20-17-25-24/travel/by,product_sku/results,13-12?language=zh-TW"

Can anyone tell me how to fix it...thx a lot