Skip to content

Commit

Permalink
Merged PR 55936: Use formatPriceValue to round all price figures
Browse files Browse the repository at this point in the history
## What's being changed

The Product model for catalog sync.

## Why it's being changed

If a tax rate had more than 2 decimal places, we were seeing `incl_tax` figures with more than 2 decimal places as well. Now we use the same utility method to format all price values in the same way.

## How to review / test this change

- Set up a tax zone with a rate like 20.4532
- Apply this rate to your catalog with a tax rule and see this applied on the storefront
- Run catalog sync
- Ensure that price, specialPrice, price_incl_tax and specialPrice_incl_tax are rounded to 2 decimal places

Related work items: #258489
  • Loading branch information
sta1r committed Jul 15, 2024
1 parent 94b4c68 commit f40bff7
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions Model/Connector/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ private function setPrices($product)
$price = $product->getPrice();
$specialPrice = $product->getSpecialPrice();
}
$this->formatPriceValues($price, $specialPrice);
$this->price = $this->formatPriceValue($price);
$this->specialPrice = $this->formatPriceValue($specialPrice);
}

/**
Expand All @@ -451,33 +452,29 @@ private function setPricesIncTax($product, $storeId)
null,
$storeId
);
$this->price_incl_tax = $this->price + ($this->price * ($rate / 100));
$this->specialPrice_incl_tax = $this->specialPrice + ($this->specialPrice * ($rate / 100));
$this->price_incl_tax = $this->formatPriceValue(
$this->price + ($this->price * ($rate / 100))
);
$this->specialPrice_incl_tax = $this->formatPriceValue(
$this->specialPrice + ($this->specialPrice * ($rate / 100))
);
}

/**
* Formats the price values.
* Formats a price value.
*
* @param float|null $price
* @param float|null $specialPrice
*
* @return void
* @return float
*/
private function formatPriceValues($price, $specialPrice)
private function formatPriceValue($price): float
{
$this->price = (float) number_format(
return (float) number_format(
(float) $price,
2,
'.',
''
);

$this->specialPrice = (float) number_format(
(float) $specialPrice,
2,
'.',
''
);
}

/**
Expand Down

0 comments on commit f40bff7

Please sign in to comment.