Skip to content

Commit

Permalink
Changing the $discount property to string instead of float to avoid a…
Browse files Browse the repository at this point in the history
… conversion between string and float when loading the entity (and hence triggering a dirty Promotion entity)
  • Loading branch information
loevgaard committed Jan 9, 2025
1 parent e918494 commit f967889
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Model/Promotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class Promotion implements PromotionInterface
/** @var Collection<array-key, PromotionRuleInterface> */
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<array-key, BaseChannelInterface> */
protected Collection $channels;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f967889

Please sign in to comment.