Skip to content

Commit f967889

Browse files
committed
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)
1 parent e918494 commit f967889

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Model/Promotion.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ class Promotion implements PromotionInterface
4343
/** @var Collection<array-key, PromotionRuleInterface> */
4444
protected Collection $rules;
4545

46-
protected float $discount = 0.0;
46+
/**
47+
* The discount is saved as a decimal type in Doctrine to avoid floating point issues
48+
*/
49+
protected string $discount = '0.0';
4750

4851
/** @var Collection<array-key, BaseChannelInterface> */
4952
protected Collection $channels;
@@ -205,7 +208,7 @@ public function removeRule(PromotionRuleInterface $rule): void
205208

206209
public function getDiscount(): float
207210
{
208-
return $this->discount;
211+
return (float) $this->discount;
209212
}
210213

211214
public function getDisplayableDiscount(): float
@@ -215,7 +218,7 @@ public function getDisplayableDiscount(): float
215218

216219
public function setDiscount(float $discount): void
217220
{
218-
$this->discount = $discount;
221+
$this->discount = (string) $discount;
219222
}
220223

221224
public function getChannels(): Collection

0 commit comments

Comments
 (0)