From 3904387913928620e7b856522cd21a95a587d358 Mon Sep 17 00:00:00 2001 From: neeta-wagento Date: Sun, 7 Jan 2018 14:56:51 +0530 Subject: [PATCH 1/6] commit for minimum order notice currency conversion issue in notice message --- .../MinimumOrderAmount/ValidationMessage.php | 24 ++++++++----- .../ValidationMessageTest.php | 36 +++++++++++-------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php index 3113721f8a597..1854689e7ae52 100644 --- a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php +++ b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php @@ -19,22 +19,32 @@ class ValidationMessage /** * @var \Magento\Framework\Locale\CurrencyInterface + * @deprecated since 101.0.0 */ private $currency; + /** + * @var \Magento\Framework\Pricing\Helper\Data + */ + private $priceHelper; + /** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Locale\CurrencyInterface $currency + * @param \Magento\Framework\Pricing\Helper\Data $priceHelper */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Locale\CurrencyInterface $currency + \Magento\Framework\Locale\CurrencyInterface $currency, + \Magento\Framework\Pricing\Helper\Data $priceHelper ) { $this->scopeConfig = $scopeConfig; $this->storeManager = $storeManager; $this->currency = $currency; + $this->priceHelper = $priceHelper ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Pricing\Helper\Data::class); } /** @@ -50,13 +60,11 @@ public function getMessage() \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); if (!$message) { - $currencyCode = $this->storeManager->getStore()->getCurrentCurrencyCode(); - $minimumAmount = $this->currency->getCurrency($currencyCode)->toCurrency( - $this->scopeConfig->getValue( - 'sales/minimum_order/amount', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) - ); + $minimumAmount = $this->priceHelper->currency($this->scopeConfig->getValue( + 'sales/minimum_order/amount', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ), true, false); + $message = __('Minimum order amount is %1', $minimumAmount); } else { //Added in order to address the issue: https://github.com/magento/magento2/issues/8287 diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php index 64204ea1fb93d..48a90aa6b0954 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php @@ -21,24 +21,33 @@ class ValidationMessageTest extends \PHPUnit\Framework\TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject + * @deprecated since 101.0.0 */ private $storeManagerMock; /** * @var \PHPUnit_Framework_MockObject_MockObject + * @deprecated since 101.0.0 */ private $currencyMock; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $priceHelperMock; + protected function setUp() { $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); $this->currencyMock = $this->createMock(\Magento\Framework\Locale\CurrencyInterface::class); + $this->priceHelperMock = $this->createMock(\Magento\Framework\Pricing\Helper\Data::class); $this->model = new \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage( $this->scopeConfigMock, $this->storeManagerMock, - $this->currencyMock + $this->currencyMock, + $this->priceHelperMock ); } @@ -58,20 +67,17 @@ public function testGetMessage() ->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) ->willReturn($minimumAmount); - $storeMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getCurrentCurrencyCode']); - $storeMock->expects($this->once())->method('getCurrentCurrencyCode')->willReturn($currencyCode); - $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); - - $currencyMock = $this->createMock(\Magento\Framework\Currency::class); - $this->currencyMock->expects($this->once()) - ->method('getCurrency') - ->with($currencyCode) - ->willReturn($currencyMock); - - $currencyMock->expects($this->once()) - ->method('toCurrency') - ->with($minimumAmount) - ->willReturn($minimumAmountCurrency); + $this->priceHelperMock->expects( + $this->once() + )->method( + 'currency' + )->with( + $minimumAmount, + true, + false + )->will( + $this->returnValue($minimumAmountCurrency) + ); $this->assertEquals( __('Minimum order amount is %1', $minimumAmountCurrency), From 5665548e3013696872c0e8c1721f5c8287260e2f Mon Sep 17 00:00:00 2001 From: neeta-wagento Date: Sun, 7 Jan 2018 15:05:51 +0530 Subject: [PATCH 2/6] make it inline --- .../MinimumOrderAmount/ValidationMessageTest.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php index 48a90aa6b0954..fe27aa7c15fc1 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php @@ -67,17 +67,10 @@ public function testGetMessage() ->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) ->willReturn($minimumAmount); - $this->priceHelperMock->expects( - $this->once() - )->method( - 'currency' - )->with( - $minimumAmount, - true, - false - )->will( - $this->returnValue($minimumAmountCurrency) - ); + $this->priceHelperMock->expects($this->once()) + ->method('currency') + ->with($minimumAmount, true, false) + ->will($this->returnValue($minimumAmountCurrency)); $this->assertEquals( __('Minimum order amount is %1', $minimumAmountCurrency), From daf95b8737cab16ccd7a00d43897641dd6e7071f Mon Sep 17 00:00:00 2001 From: neeta-wagento Date: Sun, 7 Jan 2018 15:37:37 +0530 Subject: [PATCH 3/6] make existing non usable constructor parameter as null --- .../Quote/Validator/MinimumOrderAmount/ValidationMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php index 1854689e7ae52..791775d1108af 100644 --- a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php +++ b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php @@ -37,7 +37,7 @@ class ValidationMessage public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Locale\CurrencyInterface $currency, + \Magento\Framework\Locale\CurrencyInterface $currency = null, \Magento\Framework\Pricing\Helper\Data $priceHelper ) { $this->scopeConfig = $scopeConfig; From 032242c0b2bea070ff277aa27467f17cb15f0349 Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Sun, 7 Jan 2018 17:45:18 +0530 Subject: [PATCH 4/6] Minor update to support backward compatibility --- .../Quote/Validator/MinimumOrderAmount/ValidationMessage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php index 791775d1108af..38bfcbf1d30ca 100644 --- a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php +++ b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php @@ -37,8 +37,8 @@ class ValidationMessage public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Locale\CurrencyInterface $currency = null, - \Magento\Framework\Pricing\Helper\Data $priceHelper + \Magento\Framework\Locale\CurrencyInterface $currency, + \Magento\Framework\Pricing\Helper\Data $priceHelper = null ) { $this->scopeConfig = $scopeConfig; $this->storeManager = $storeManager; From 6e060e8ef03da150fba251e73f378b8241b3403b Mon Sep 17 00:00:00 2001 From: neeta-wagento Date: Mon, 8 Jan 2018 14:46:43 +0530 Subject: [PATCH 5/6] resolve test issues --- .../MinimumOrderAmount/ValidationMessage.php | 4 ++-- .../ValidationMessageTest.php | 19 +++---------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php index 791775d1108af..38bfcbf1d30ca 100644 --- a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php +++ b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php @@ -37,8 +37,8 @@ class ValidationMessage public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Locale\CurrencyInterface $currency = null, - \Magento\Framework\Pricing\Helper\Data $priceHelper + \Magento\Framework\Locale\CurrencyInterface $currency, + \Magento\Framework\Pricing\Helper\Data $priceHelper = null ) { $this->scopeConfig = $scopeConfig; $this->storeManager = $storeManager; diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php index fe27aa7c15fc1..65768b08c37ec 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php @@ -21,7 +21,6 @@ class ValidationMessageTest extends \PHPUnit\Framework\TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject - * @deprecated since 101.0.0 */ private $storeManagerMock; @@ -55,29 +54,17 @@ public function testGetMessage() { $minimumAmount = 20; $minimumAmountCurrency = '$20'; - $currencyCode = 'currency_code'; + $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(null); - $this->scopeConfigMock->expects($this->at(0)) - ->method('getValue') - ->with('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) - ->willReturn(null); - - $this->scopeConfigMock->expects($this->at(1)) - ->method('getValue') - ->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) - ->willReturn($minimumAmount); + $this->scopeConfigMock->expects($this->at(1))->method('getValue')->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn($minimumAmount); $this->priceHelperMock->expects($this->once()) ->method('currency') ->with($minimumAmount, true, false) ->will($this->returnValue($minimumAmountCurrency)); - $this->assertEquals( - __('Minimum order amount is %1', $minimumAmountCurrency), - $this->model->getMessage() - ); + $this->assertEquals(__('Minimum order amount is %1', $minimumAmountCurrency), $this->model->getMessage()); } - public function testGetConfigMessage() { $configMessage = 'config_message'; From 74901e41f66b79ff4a7a87dfb4730a05e6b046c9 Mon Sep 17 00:00:00 2001 From: neeta-wagento Date: Mon, 8 Jan 2018 15:07:33 +0530 Subject: [PATCH 6/6] resolve intendent issues --- .../MinimumOrderAmount/ValidationMessageTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php index 65768b08c37ec..272a4e3a4ba49 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php @@ -54,9 +54,15 @@ public function testGetMessage() { $minimumAmount = 20; $minimumAmountCurrency = '$20'; - $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(null); + $this->scopeConfigMock->expects($this->at(0)) + ->method('getValue') + ->with('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->willReturn(null); - $this->scopeConfigMock->expects($this->at(1))->method('getValue')->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn($minimumAmount); + $this->scopeConfigMock->expects($this->at(1)) + ->method('getValue') + ->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->willReturn($minimumAmount); $this->priceHelperMock->expects($this->once()) ->method('currency')