Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Tierprice can t save float percentage value 18651 #22936

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/code/Magento/Catalog/Pricing/Render/PriceBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Pricing\Render;

use Magento\Catalog\Model\Product;
Expand Down Expand Up @@ -71,7 +73,9 @@ public function jsonEncode($valueToEncode)
*
* @param int $length
* @param string|null $chars
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getRandomString($length, $chars = null)
{
Expand All @@ -93,4 +97,21 @@ public function getCanDisplayQty(Product $product)
}
return true;
}

/**
* Format percent
*
* @param float $percent
*
* @return string
*/
public function formatPercent(float $percent): string
{
/*First rtrim - trim zeros. So, 10.00 -> 10.*/
/*Second rtrim - trim dot. So, 10. -> 10*/
return rtrim(
rtrim(number_format($percent, 2), '0'),
'.'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ $product = $block->getSaleableItem();
$price['price_qty'],
$priceAmountBlock,
$index,
$tierPriceModel->getSavePercent($price['price'])
$block->formatPercent($price['percentage_value'] ?? $tierPriceModel->getSavePercent($price['price']))
)
: __('Buy %1 for %2 each', $price['price_qty'], $priceAmountBlock);
?>
Expand Down