Author Topic: PHP Warning: A non-numeric value encountered in weight_countries.php  (Read 201 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: 1224
    • 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: 26491
  • 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 VM3.2.12.9708 on Joomla 3.8.3 PHP 7.0.25

Testing VM3.2.12.9708 on J3.8.3

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: 9450
  • 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/