VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: hsoft on January 04, 2018, 15:43:06 PM

Title: PHP Warning: A non-numeric value encountered in weight_countries.php
Post by: hsoft on January 04, 2018, 15:43:06 PM
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'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.
Title: Re: PHP Warning: A non-numeric value encountered in weight_countries.php
Post by: Jörgen on January 04, 2018, 21:23:02 PM
Turn off warning report to get rid of the message. It is only a warning, not an error.

regards

Jörgen @ Kreativ Fotografi
Title: Re: PHP Warning: A non-numeric value encountered in weight_countries.php
Post by: jenkinhill on January 05, 2018, 11:25:12 AM
http://forum.virtuemart.net/index.php?topic=102555.0
Title: Re: PHP Warning: A non-numeric value encountered in weight_countries.php
Post by: hsoft on January 08, 2018, 09:57:27 AM
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...
Title: Re: PHP Warning: A non-numeric value encountered in weight_countries.php
Post by: 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
Title: Re: PHP Warning: A non-numeric value encountered in weight_countries.php
Post by: anantmaks on February 12, 2018, 12:46:11 PM
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.