Author Topic: PHP Warning: A non-numeric value encountered in weight_countries.php  (Read 1244 times)

hsoft

  • Beginner
  • *
  • Posts: 3
  • A beginner
  • VirtueMart Version: 3.2.12
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

  • Global Moderator
  • Full Member
  • *
  • Posts: 1804
    • Kreativ Fotografi
  • VirtueMart Version: 3.2.12
Re: PHP Warning: A non-numeric value encountered in weight_countries.php
« Reply #1 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
Joomla 3.8.3
Virtuemart 3.2.12
Olympiantheme Hera (customized)

jenkinhill

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 27099
  • Always on vacation
    • Jenkin Hill Internet
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

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

Currently using VM 3.4.3.9989 on Joomla 3.9.1 PHP 7.0.32
Testing VM 3.4.3.9993 on Joomla 3.9.1

hsoft

  • Beginner
  • *
  • Posts: 3
  • A beginner
  • VirtueMart Version: 3.2.12
Re: PHP Warning: A non-numeric value encountered in weight_countries.php
« Reply #3 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...

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9743
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: PHP Warning: A non-numeric value encountered in weight_countries.php
« Reply #4 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
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

anantmaks

  • Beginner
  • *
  • Posts: 43
  • Indian Software Engineer
Re: PHP Warning: A non-numeric value encountered in weight_countries.php
« Reply #5 on: February 12, 2018, 12:46:11 pm »
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