From f967889659629a4f94d9eae8c956df32c3bee6de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Thu, 9 Jan 2025 10:18:42 +0100 Subject: [PATCH] Changing the $discount property to string instead of float to avoid a conversion between string and float when loading the entity (and hence triggering a dirty Promotion entity) --- src/Model/Promotion.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Model/Promotion.php b/src/Model/Promotion.php index 2bcc20c..852b915 100644 --- a/src/Model/Promotion.php +++ b/src/Model/Promotion.php @@ -43,7 +43,10 @@ class Promotion implements PromotionInterface /** @var Collection */ protected Collection $rules; - protected float $discount = 0.0; + /** + * The discount is saved as a decimal type in Doctrine to avoid floating point issues + */ + protected string $discount = '0.0'; /** @var Collection */ protected Collection $channels; @@ -205,7 +208,7 @@ public function removeRule(PromotionRuleInterface $rule): void public function getDiscount(): float { - return $this->discount; + return (float) $this->discount; } public function getDisplayableDiscount(): float @@ -215,7 +218,7 @@ public function getDisplayableDiscount(): float public function setDiscount(float $discount): void { - $this->discount = $discount; + $this->discount = (string) $discount; } public function getChannels(): Collection