From 63bc3338744e20e73602bd76c8cd6c89681e53de Mon Sep 17 00:00:00 2001 From: Neeta Kangiya Date: Tue, 5 Jun 2018 14:32:22 +0530 Subject: [PATCH 1/7] Update Collection.php --- .../Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php index 70d576c83e554..787a20d7ffb75 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php @@ -95,7 +95,7 @@ protected function _construct() */ public function getStoreId() { - return (int)$this->_quote->getStoreId(); + return (int)$this->_productCollectionFactory->create()->getStoreId(); } /** From c261156c46b3211564056866cdb436b7cfd2ca9d Mon Sep 17 00:00:00 2001 From: neeta-wagento Date: Mon, 30 Oct 2017 15:24:50 +0530 Subject: [PATCH 2/7] resolve Error While Trying To Load Quote Item Collection Using Magento\Quote\Model\ResourceModel\QuoteItem\Collection::getItems() --- .../Quote/Model/ResourceModel/Quote/Item/Collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php index 6782dec79fd2f..5aac11ac62dff 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php @@ -89,13 +89,13 @@ protected function _construct() } /** - * Retrieve store Id (From Quote) + * Retrieve store Id (From Quote) * * @return int */ public function getStoreId() { - return (int)$this->_quote->getStoreId(); + return (int)$this->_productCollectionFactory->create()->getStoreId(); } /** From 950e3170e5d17a3f420605cec8c07d096d3ccd0a Mon Sep 17 00:00:00 2001 From: neeta-wagento Date: Mon, 30 Oct 2017 16:54:35 +0530 Subject: [PATCH 3/7] Update Collection.php Resolve Space Issue --- .../Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php index 5aac11ac62dff..161ff159a2df9 100644 --- a/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php +++ b/app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php @@ -89,7 +89,7 @@ protected function _construct() } /** - * Retrieve store Id (From Quote) + * Retrieve store Id (From Quote) * * @return int */ From 913867d8bb64f75061049066010f34d454aee7e5 Mon Sep 17 00:00:00 2001 From: Neeta Kangiya Date: Tue, 5 Jun 2018 15:13:59 +0530 Subject: [PATCH 4/7] Update ValidationMessage.php --- .../MinimumOrderAmount/ValidationMessage.php | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 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 6e372d223fdac..38bfcbf1d30ca 100644 --- a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php +++ b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php @@ -19,26 +19,38 @@ 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 = null ) { $this->scopeConfig = $scopeConfig; $this->storeManager = $storeManager; $this->currency = $currency; + $this->priceHelper = $priceHelper ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Pricing\Helper\Data::class); } /** - * @return \Magento\Framework\Phrase|mixed + * Get validation message. + * + * @return \Magento\Framework\Phrase * @throws \Zend_Currency_Exception */ public function getMessage() @@ -48,14 +60,15 @@ 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 + $message = __($message); } return $message; From f46b08a1348f3ae13ca64b68d05e2910cdd133e5 Mon Sep 17 00:00:00 2001 From: Neeta Kangiya Date: Tue, 5 Jun 2018 15:38:03 +0530 Subject: [PATCH 5/7] Update ValidationMessageTest.php --- .../ValidationMessageTest.php | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 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 c61820ddbbd18..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 @@ -5,7 +5,9 @@ */ namespace Magento\Quote\Test\Unit\Model\Quote\Validator\MinimumOrderAmount; -class ValidationMessageTest extends \PHPUnit_Framework_TestCase +use Magento\Framework\Phrase; + +class ValidationMessageTest extends \PHPUnit\Framework\TestCase { /** * @var \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage @@ -24,19 +26,27 @@ class ValidationMessageTest extends \PHPUnit_Framework_TestCase /** * @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->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); - $this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class); - $this->currencyMock = $this->getMock(\Magento\Framework\Locale\CurrencyInterface::class); + $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 ); } @@ -44,8 +54,6 @@ 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) @@ -56,28 +64,13 @@ public function testGetMessage() ->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) ->willReturn($minimumAmount); - $storeMock = $this->getMock(\Magento\Store\Model\Store::class, ['getCurrentCurrencyCode'], [], '', false); - $storeMock->expects($this->once())->method('getCurrentCurrencyCode')->willReturn($currencyCode); - $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); + $this->priceHelperMock->expects($this->once()) + ->method('currency') + ->with($minimumAmount, true, false) + ->will($this->returnValue($minimumAmountCurrency)); - - $currencyMock = $this->getMock(\Magento\Framework\Currency::class, [], [], '', false); - $this->currencyMock->expects($this->once()) - ->method('getCurrency') - ->with($currencyCode) - ->willReturn($currencyMock); - - $currencyMock->expects($this->once()) - ->method('toCurrency') - ->with($minimumAmount) - ->willReturn($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'; @@ -86,6 +79,9 @@ public function testGetConfigMessage() ->with('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) ->willReturn($configMessage); - $this->assertEquals($configMessage, $this->model->getMessage()); + $message = $this->model->getMessage(); + + $this->assertEquals(Phrase::class, get_class($message)); + $this->assertEquals($configMessage, $message->__toString()); } } From 8b26946dad4eeadcb5bbe9bcf232be8e93704fb3 Mon Sep 17 00:00:00 2001 From: Neeta Kangiya Date: Thu, 7 Jun 2018 15:49:18 +0530 Subject: [PATCH 6/7] Update ValidationMessage.php --- .../Validator/MinimumOrderAmount/ValidationMessage.php | 6 +----- 1 file changed, 1 insertion(+), 5 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 38bfcbf1d30ca..fa9fda46095b7 100644 --- a/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php +++ b/app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php @@ -64,13 +64,9 @@ public function getMessage() '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 - $message = __($message); } - return $message; } } From 029fd480f1507ea5b48dc43f7bc055c25bdaef35 Mon Sep 17 00:00:00 2001 From: Neeta Kangiya Date: Wed, 13 Jun 2018 16:53:27 +0530 Subject: [PATCH 7/7] Update ValidationMessageTest.php --- .../Validator/MinimumOrderAmount/ValidationMessageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 272a4e3a4ba49..81abe2f901623 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 @@ -7,7 +7,7 @@ use Magento\Framework\Phrase; -class ValidationMessageTest extends \PHPUnit\Framework\TestCase +class ValidationMessageTest extends \PHPUnit_Framework_TestCase { /** * @var \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage