From 60eefc647e0f02905b8fd3689913bc46180828b0 Mon Sep 17 00:00:00 2001 From: emirajbbd Date: Thu, 19 Sep 2019 04:07:18 +0600 Subject: [PATCH] Fixed PHP Error: A non-numeric value encountered It sends PHP Warning and break execution of functions while boxes have other attributes except length, width, height. Example: array( [sku] => UNIID, [weight] => 0.0000, [qty] => 1,[baserowtotal] => 0.0000,[length] => 85,[width] => 3, [height] => 2 --- src/Packer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Packer.php b/src/Packer.php index 17bf60e..d8e94c8 100644 --- a/src/Packer.php +++ b/src/Packer.php @@ -342,9 +342,9 @@ public function _get_volume($box) throw new \InvalidArgumentException("_get_volume function only accepts arrays with 3 values (length, width, height)"); } - $box = array_values($box); - - return $box[0] * $box[1] * $box[2]; + $box = array_filter($box, 'strlen'); + + return (isset($box['length'])?$box['length']:$box[0]) * (isset($box['width'])?$box['width']:$box[1]) * (isset($box['height'])?$box['height']:$box[2]);; } /** @@ -554,4 +554,4 @@ private function _fill_space($space) } } } -} \ No newline at end of file +}