From e7a1b33ae6993ba3ad631a31d62bbdc67fbb2784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 3 Jul 2023 22:15:58 +0200 Subject: [PATCH] Allow to set the exchange rate of a currency to null (not existing) after it was set once --- src/Entity/PriceInformations/Currency.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Entity/PriceInformations/Currency.php b/src/Entity/PriceInformations/Currency.php index 889bc7c8..80fe6c5e 100644 --- a/src/Entity/PriceInformations/Currency.php +++ b/src/Entity/PriceInformations/Currency.php @@ -157,12 +157,15 @@ class Currency extends AbstractStructuralDBElement */ public function setExchangeRate(?BigDecimal $exchange_rate): self { - if (!$exchange_rate instanceof BigDecimal) { + //If the exchange rate is null, set it to null and return. + if ($exchange_rate === null) { $this->exchange_rate = null; + return $this; } - $tmp = $exchange_rate->toScale(self::PRICE_SCALE, RoundingMode::HALF_UP); + //Only change the object, if the value changes, so that doctrine does not detect it as changed. - if ((string) $tmp !== (string) $this->exchange_rate) { + //Or if the current exchange rate is currently null, as we can not compare it then + if ($this->exchange_rate === null || $exchange_rate->compareTo($this->exchange_rate) !== 0) { $this->exchange_rate = $exchange_rate; }