Skip to content

Commit 3904387

Browse files
committed
commit for minimum order notice currency conversion issue in notice message
1 parent 816ec39 commit 3904387

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,32 @@ class ValidationMessage
1919

2020
/**
2121
* @var \Magento\Framework\Locale\CurrencyInterface
22+
* @deprecated since 101.0.0
2223
*/
2324
private $currency;
2425

26+
/**
27+
* @var \Magento\Framework\Pricing\Helper\Data
28+
*/
29+
private $priceHelper;
30+
2531
/**
2632
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
2733
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
2834
* @param \Magento\Framework\Locale\CurrencyInterface $currency
35+
* @param \Magento\Framework\Pricing\Helper\Data $priceHelper
2936
*/
3037
public function __construct(
3138
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
3239
\Magento\Store\Model\StoreManagerInterface $storeManager,
33-
\Magento\Framework\Locale\CurrencyInterface $currency
40+
\Magento\Framework\Locale\CurrencyInterface $currency,
41+
\Magento\Framework\Pricing\Helper\Data $priceHelper
3442
) {
3543
$this->scopeConfig = $scopeConfig;
3644
$this->storeManager = $storeManager;
3745
$this->currency = $currency;
46+
$this->priceHelper = $priceHelper ?: \Magento\Framework\App\ObjectManager::getInstance()
47+
->get(\Magento\Framework\Pricing\Helper\Data::class);
3848
}
3949

4050
/**
@@ -50,13 +60,11 @@ public function getMessage()
5060
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
5161
);
5262
if (!$message) {
53-
$currencyCode = $this->storeManager->getStore()->getCurrentCurrencyCode();
54-
$minimumAmount = $this->currency->getCurrency($currencyCode)->toCurrency(
55-
$this->scopeConfig->getValue(
56-
'sales/minimum_order/amount',
57-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
58-
)
59-
);
63+
$minimumAmount = $this->priceHelper->currency($this->scopeConfig->getValue(
64+
'sales/minimum_order/amount',
65+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
66+
), true, false);
67+
6068
$message = __('Minimum order amount is %1', $minimumAmount);
6169
} else {
6270
//Added in order to address the issue: https://github.com/magento/magento2/issues/8287

app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,33 @@ class ValidationMessageTest extends \PHPUnit\Framework\TestCase
2121

2222
/**
2323
* @var \PHPUnit_Framework_MockObject_MockObject
24+
* @deprecated since 101.0.0
2425
*/
2526
private $storeManagerMock;
2627

2728
/**
2829
* @var \PHPUnit_Framework_MockObject_MockObject
30+
* @deprecated since 101.0.0
2931
*/
3032
private $currencyMock;
3133

34+
/**
35+
* @var \PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
private $priceHelperMock;
38+
3239
protected function setUp()
3340
{
3441
$this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
3542
$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
3643
$this->currencyMock = $this->createMock(\Magento\Framework\Locale\CurrencyInterface::class);
44+
$this->priceHelperMock = $this->createMock(\Magento\Framework\Pricing\Helper\Data::class);
3745

3846
$this->model = new \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage(
3947
$this->scopeConfigMock,
4048
$this->storeManagerMock,
41-
$this->currencyMock
49+
$this->currencyMock,
50+
$this->priceHelperMock
4251
);
4352
}
4453

@@ -58,20 +67,17 @@ public function testGetMessage()
5867
->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
5968
->willReturn($minimumAmount);
6069

61-
$storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getCurrentCurrencyCode']);
62-
$storeMock->expects($this->once())->method('getCurrentCurrencyCode')->willReturn($currencyCode);
63-
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
64-
65-
$currencyMock = $this->createMock(\Magento\Framework\Currency::class);
66-
$this->currencyMock->expects($this->once())
67-
->method('getCurrency')
68-
->with($currencyCode)
69-
->willReturn($currencyMock);
70-
71-
$currencyMock->expects($this->once())
72-
->method('toCurrency')
73-
->with($minimumAmount)
74-
->willReturn($minimumAmountCurrency);
70+
$this->priceHelperMock->expects(
71+
$this->once()
72+
)->method(
73+
'currency'
74+
)->with(
75+
$minimumAmount,
76+
true,
77+
false
78+
)->will(
79+
$this->returnValue($minimumAmountCurrency)
80+
);
7581

7682
$this->assertEquals(
7783
__('Minimum order amount is %1', $minimumAmountCurrency),

0 commit comments

Comments
 (0)