Skip to content

Commit

Permalink
Merge pull request #127 from tatiana-scandi/bugfix/2463/disc-price-ca…
Browse files Browse the repository at this point in the history
…lculation-fix

#2463 - fix price diff error caused by rounding
  • Loading branch information
carinadues authored Oct 11, 2021
2 parents 8dfec03 + 8e5ec73 commit cb91395
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Model/Resolver/Product/PriceRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,13 @@ protected function formatPrice(
protected function calculateDiscount(Product $product, float $regularPrice, float $finalPrice) : array
{
if ($product->getTypeId() !== 'bundle') {
return $this->discount->getDiscountByDifference($regularPrice, $finalPrice);
// Calculate percent_off with higher precision to avoid +/- 0.01 price differences on frontend
$priceDifference = $regularPrice - $finalPrice;

return [
'amount_off' => round($priceDifference, 2),
'percent_off' => round($priceDifference / $regularPrice * 100, 8)
];
}

// Bundle products have special price set in % (percents)
Expand Down

0 comments on commit cb91395

Please sign in to comment.