Skip to content

Commit 2c4fa07

Browse files
committed
6965: #6965: \Magento\Directory\Model\PriceCurrency::format() fails without conversion rate
1 parent 506d500 commit 2c4fa07

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

app/code/Magento/Directory/Model/PriceCurrency.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,15 @@ public function format(
7777
$scope = null,
7878
$currency = null
7979
) {
80-
return $this->getCurrency($scope, $currency)
81-
->formatPrecision($amount, $precision, [], $includeContainer);
80+
if ($currency instanceof Currency) {
81+
$currentCurrency = $currency;
82+
} elseif (is_string($currency)) {
83+
$currentCurrency = $this->currencyFactory->create()->load($currency);
84+
} else {
85+
$currentCurrency = $this->getStore($scope)->getCurrentCurrency();
86+
}
87+
88+
return $currentCurrency->formatPrecision($amount, $precision, [], $includeContainer);
8289
}
8390

8491
/**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Directory\Model;
8+
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
use PHPUnit\Framework\TestCase;
11+
12+
/**
13+
* Provide tests for PriceCurrency model.
14+
*/
15+
class PriceCurrencyTest extends TestCase
16+
{
17+
/**
18+
* Test subject.
19+
*
20+
* @var PriceCurrency
21+
*/
22+
private $priceCurrency;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp()
28+
{
29+
$this->priceCurrency = Bootstrap::getObjectManager()->get(PriceCurrency::class);
30+
}
31+
32+
/**
33+
* Check PriceCurrency::format() doesn't depend on currency rate configuration.
34+
* @return void
35+
*/
36+
public function testFormat()
37+
{
38+
self::assertSame(
39+
'<span class="price">AFN10.00</span>',
40+
$this->priceCurrency->format(10, true, 2, null, 'AFN')
41+
);
42+
}
43+
}

0 commit comments

Comments
 (0)