From 2dc703d86d66dae8994c6bbd8b7372fb5ca0d68b Mon Sep 17 00:00:00 2001 From: Jan-Erik Spreng Date: Tue, 5 Apr 2022 09:40:40 +0200 Subject: [PATCH 1/2] [KLARNASUPPORT-551] Fix compatibility to PHP 8.0 --- CHANGELOG.md | 1 + src/Components/Transformer/LineItemTransformer.php | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1308f94..20dba90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip ### Fixed - Fixed a missing auth header during customer token generation - Fixed the config reader to return the correct value when falsy values are configured (e.g. 0, 'false') +- Fixed compatibility to PHP 8.0 ### Added - Allowed manual and individual adding of positions which are not related to an article diff --git a/src/Components/Transformer/LineItemTransformer.php b/src/Components/Transformer/LineItemTransformer.php index bd4fb06..4f55b58 100644 --- a/src/Components/Transformer/LineItemTransformer.php +++ b/src/Components/Transformer/LineItemTransformer.php @@ -292,10 +292,14 @@ public function createShippingLineItem($shippingCostsWithTax, $shippingCostsNet, */ public function getUnitPriceWithTax(array $lineItem): float { - $netPriceIsShown = isset($lineItem['amountWithTax']) ? true : false; + $netPrice = $lineItem['amountWithTax'] ?? null; - if ($netPriceIsShown) { - return round(str_replace(',', '.', $lineItem['amountWithTax']) / $lineItem['quantity'], 2); + if ($netPrice) { + if (is_string($netPrice)) { + $netPrice = (float) str_replace(',', '.', $lineItem['amountWithTax']); + } + + return round($netPrice / $lineItem['quantity'], 2); } return (float) $lineItem['priceNumeric']; From 9a86daa4bb13a43d15eeef19a605aa097191d686 Mon Sep 17 00:00:00 2001 From: Timo Helmke Date: Tue, 5 Apr 2022 08:10:42 +0000 Subject: [PATCH 2/2] [KLARNASUPPORT-551] Add explicit check --- src/Components/Transformer/LineItemTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Transformer/LineItemTransformer.php b/src/Components/Transformer/LineItemTransformer.php index 4f55b58..e1c6932 100644 --- a/src/Components/Transformer/LineItemTransformer.php +++ b/src/Components/Transformer/LineItemTransformer.php @@ -294,7 +294,7 @@ public function getUnitPriceWithTax(array $lineItem): float { $netPrice = $lineItem['amountWithTax'] ?? null; - if ($netPrice) { + if ($netPrice !== null) { if (is_string($netPrice)) { $netPrice = (float) str_replace(',', '.', $lineItem['amountWithTax']); }