From 3b8ece6c0bbfe19312808a59569855af08591d5b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 31 Jan 2022 21:46:35 +0100 Subject: [PATCH] Fix php8 --- htdocs/product/class/product.class.php | 7 ++++--- test/phpunit/ProductTest.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 26bf4915d80..f6a201108ad 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -874,9 +874,10 @@ class Product extends CommonObject $arrayofnonnegativevalue = array('weight'=>'Weight', 'width'=>'Width', 'height'=>'Height', 'length'=>'Length', 'surface'=>'Surface', 'volume'=>'Volume'); foreach ($arrayofnonnegativevalue as $key => $value) { - if (property_exists($this, $key) && $this->$key < 0) { - $langs->load("other"); - $this->errors[] = $langs->trans("FieldCannotBeNegative", $langs->transnoentitiesnoconv($value)); + if (property_exists($this, $key) && !empty($this->$key) && ($this->$key < 0)) { + $langs->loadLangs(array("main", "other")); + $this->error = $langs->trans("FieldCannotBeNegative", $langs->transnoentitiesnoconv($value)); + $this->errors[] = $this->error; $result = -4; } } diff --git a/test/phpunit/ProductTest.php b/test/phpunit/ProductTest.php index 7eb6de57c02..90dfab3fe04 100644 --- a/test/phpunit/ProductTest.php +++ b/test/phpunit/ProductTest.php @@ -199,7 +199,7 @@ class ProductTest extends PHPUnit\Framework\TestCase $localobject->note_private = 'New private note after update'; $result=$localobject->update($localobject->id, $user); print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $this->assertLessThan($result, 0, 'Error '.$localobject->error); return $localobject; }