PHP Warning: A non-numeric value encountered in weight_countries.php

Started by hsoft, January 04, 2018, 15:43:06 PM

Previous topic - Next topic

hsoft

I often get the following PHP warning on my cart page:
Warning: A non-numeric value encountered in ... plugins\vmshipment\weight_countries\weight_countries.php on line 203.

I realised that it happens only the first time I go to cart after adding some item(s). It does not matter how I get to the cart page.

Steps to reproduce (always works):

  • I log in into VM and log out. This step is essential since the warning displayed only once.
  • Adding some products to cart
  • On the popup click on the Cart link

I've tested with the standard Joomla template (beez) too. The warning is caused because the costs are string instead of float.

The corresponding code (the line in question is bold):

function getCosts (VirtueMartCart $cart, $method, $cart_prices) {

      if ($method->free_shipment && $cart_prices['salesPrice'] >= $method->free_shipment) {
         return 0.0;
      } else {
         return $method->shipment_cost + $method->package_fee;
      }
}


Using VM 3.2.12 & Joomla 3.8.2

I think this is a bug and hope will be fixed in the next release.

Jörgen

Turn off warning report to get rid of the message. It is only a warning, not an error.

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

hsoft

Of course, I could turn off warnings (I do so in my production environment), but the problem won't be solved by this. The solution would be fixing the code so the strings would be used as strings and not float numbers...

Milbo

what happens with

return (float)$method->shipment_cost + (float)$method->package_fee;

??

Seems one of the params is "" and not 0.0
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

anantmaks

Quote from: Milbo on January 08, 2018, 11:46:25 AM
what happens with

return (float)$method->shipment_cost + (float)$method->package_fee;

??

Seems one of the params is "" and not 0.0

Yes, this is what should be done, the issue arising as if we do not pass values in 'package fee' and 'minimum Amount for Free Shipment' in weight_countries then it doesn't fill it as 0, rather consider it as a string. Though it fills 'Shipment Cost' as 0 when left blank and saved. This is the default vmshipment, and it should have done it. Anyways that's an additional plugin only. The concern is, a similar issue arises from 'vmpsplugin.php', even payment plugin parameter coming as string causes this warning to occur. I hope parsing will be done in algebraic calculations, in coming versions of VirtueMart.
Anant Garg
Ghaziabad, India