Author Topic: Division by Zero on com_virtuemart/models/product.php [SOLVED]  (Read 19180 times)

inopia

  • Beginner
  • *
  • Posts: 12
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.

inopia

  • Beginner
  • *
  • Posts: 12
Re: Division by Zero on com_virtuemart/models/product.php
« Reply #1 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


bytelord

  • Nikos
  • Global Moderator
  • Full Member
  • *
  • Posts: 2369
Re: Division by Zero on com_virtuemart/models/product.php
« Reply #2 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
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

bytelord

  • Nikos
  • Global Moderator
  • Full Member
  • *
  • Posts: 2369
Re: Division by Zero on com_virtuemart/models/product.php
« Reply #3 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.
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

inopia

  • Beginner
  • *
  • Posts: 12
Re: Division by Zero on com_virtuemart/models/product.php
« Reply #4 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.

bytelord

  • Nikos
  • Global Moderator
  • Full Member
  • *
  • Posts: 2369
Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
« Reply #5 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.
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

inopia

  • Beginner
  • *
  • Posts: 12
Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
« Reply #6 on: July 02, 2012, 16:37:24 pm »
"It's not a bug; it's an undocumented feature!" LOL

vynette

  • Beginner
  • *
  • Posts: 5
Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
« Reply #7 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.

inopia

  • Beginner
  • *
  • Posts: 12
Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
« Reply #8 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.

esanchez1091

  • Beginner
  • *
  • Posts: 6
Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
« Reply #9 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]

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10530
  • VM4.0.7 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
« Reply #10 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
Code: [Select]
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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bytelord

  • Nikos
  • Global Moderator
  • Full Member
  • *
  • Posts: 2369
Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
« Reply #11 on: July 02, 2012, 23:12:29 pm »
Thank you for the code snippet.
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

inopia

  • Beginner
  • *
  • Posts: 12
Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
« Reply #12 on: July 03, 2012, 09:40:04 am »
Thank you for the code.

cecilia2330

  • Beginner
  • *
  • Posts: 15
Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
« Reply #13 on: July 03, 2012, 18:47:49 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
Code: [Select]
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

Loris

  • Beginner
  • *
  • Posts: 30
Re: Division by Zero on com_virtuemart/models/product.php [SOLVED]
« Reply #14 on: July 03, 2012, 19:09:57 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
Code: [Select]
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
Code: [Select]
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