Updating to J 4.2.1 then adding something to cart gives division by zero

  • Posts: 290
  • Thank you received: 22
1 year 7 months ago #344289

-- HikaShop version -- : 4.6.1
-- Joomla version -- : 4.2.1
-- PHP version -- : 8.0

After I updated my dev site to Joomla 4.2.1 and updated to the latest HikaShop yesterday I noticed that adding anything to the cart is not working anymore. In the console I see that the answer is "Division by zero"
The same goes for clicking the cart menu-item.

Any thoughts ?

Last edit: 1 year 7 months ago by nico.van.leeuwen. Reason: solved

Please Log in or Create an account to join the conversation.

  • Posts: 81539
  • Thank you received: 13069
  • MODERATOR
1 year 7 months ago #344302

Hi,

I also updated to the 4.2.1 and used the latest build of HikaShop 4.6.1 but I didn't get the error when trying to reproduce.
Could you please activate the "debug system" setting of the Joomla configuration and try again ? Then, please provide the full error message's screenshot.

Please Log in or Create an account to join the conversation.

  • Posts: 290
  • Thank you received: 22
1 year 7 months ago #344333

Hi Nicolas,

I've turned every logging on and can see this in the logs :

2022-09-01T18:38:34+00:00 CRITICAL 77.63.33.55 error Uncaught Throwable of type DivisionByZeroError thrown with message "Division by zero". Stack trace: #0 [ROOT]/administrator/components/com_hikashop/helpers/shippingplugin.php(69): hikashopCurrencyClass->convertUniquePrice()
#1 [ROOT]/libraries/src/Plugin/CMSPlugin.php(279): hikashopShippingPlugin->onShippingDisplay()
#2 [ROOT]/libraries/vendor/joomla/event/src/Dispatcher.php(486): Joomla\CMS\Plugin\CMSPlugin->Joomla\CMS\Plugin\{closure}()
#3 [ROOT]/libraries/src/Application/EventAware.php(107): Joomla\Event\Dispatcher->dispatch()
#4 [ROOT]/administrator/components/com_hikashop/classes/shipping.php(434): Joomla\CMS\Application\WebApplication->triggerEvent()
#5 [ROOT]/administrator/components/com_hikashop/classes/cart.php(1345): hikashopShippingClass->getShippings()
#6 [ROOT]/components/com_hikashop/controllers/product.php(548): hikashopCartClass->getFullCart()
#7 [ROOT]/libraries/src/MVC/Controller/BaseController.php(672): productController->updatecart()
#8 [ROOT]/administrator/components/com_hikashop/helpers/helper.php(2382): Joomla\CMS\MVC\Controller\BaseController->execute()
#9 [ROOT]/components/com_hikashop/hikashop.php(88): hikashopController->execute()
#10 [ROOT]/libraries/src/Dispatcher/LegacyComponentDispatcher.php(71): require_once('/home/swanndev/...')
#11 [ROOT]/libraries/src/Dispatcher/LegacyComponentDispatcher.php(73): Joomla\CMS\Dispatcher\LegacyComponentDispatcher::Joomla\CMS\Dispatcher\{closure}()
#12 [ROOT]/libraries/src/Component/ComponentHelper.php(355): Joomla\CMS\Dispatcher\LegacyComponentDispatcher->dispatch()
#13 [ROOT]/libraries/src/Application/SiteApplication.php(200): Joomla\CMS\Component\ComponentHelper::renderComponent()
#14 [ROOT]/libraries/src/Application/SiteApplication.php(241): Joomla\CMS\Application\SiteApplication->dispatch()
#15 [ROOT]/libraries/src/Application/CMSApplication.php(294): Joomla\CMS\Application\SiteApplication->doExecute()
#16 [ROOT]/includes/app.php(61): Joomla\CMS\Application\CMSApplication->execute()
#17 [ROOT]/index.php(32): require_once('/home/swanndev/...')
#18 {main}

And what I see it something that could be related to shipping?

I hope this is useful.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 81539
  • Thank you received: 13069
  • MODERATOR
1 year 7 months ago #344334

Hi,

The issue comes from the fact you've updated PHP to 8 and you have a currency with a rate of 0 with a currency setup requiring a price to be converted between two currencies with one with that rate set to 0, which is not possible. A currency rate should normally never be 0 since that would mean it is not possible to convert.
So while we need to modify the code so that even if someone put 0 in a rate, it doesn't crash, the error you have is not really a problem as that's not something that should happen. Just set a rate in your currencies and the error won't happen.

Please Log in or Create an account to join the conversation.

  • Posts: 290
  • Thank you received: 22
1 year 7 months ago #344365

Hi Nicolas,

I just checked the currencies but did not find any with a rate of zero.
After updating the rates I still cannot add anything to the cart resulting in the same error.
Just to be certain I sorted the rates to see if I was not mistaken, no currency goes to 0.

Also I was running PHP 8 since starting this site buildt so it does not look like this has any part in this issue.

No problem if you want to take a quick look, I can create an Super User for temp access.

Please Log in or Create an account to join the conversation.

  • Posts: 81539
  • Thank you received: 13069
  • MODERATOR
1 year 7 months ago #344400

Hi,

It's strange then.
Change the line:

$price = floatval($price) / floatval($srcCurrency->currency_rate);
to:
if(!empty($srcCurrency->currency_rate) && $srcCurrency->currency_rate > 0.0) {
				$price = floatval($price) / floatval($srcCurrency->currency_rate);
			}
in the file administrator/components/com_hikashop/classes/currency.php
That's the fix I've made for the error and which will be in the next version of HikaShop.
It should be effective.

Please Log in or Create an account to join the conversation.

  • Posts: 290
  • Thank you received: 22
1 year 7 months ago #344461

Hi Nicolas,

Thanks, that did the trick.

Nico

The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.065 seconds
Powered by Kunena Forum