Skip to content
Snippets Groups Projects
Commit 25e46719 authored by Ievgen Shakhsuvarov's avatar Ievgen Shakhsuvarov Committed by GitHub
Browse files

MAGETWO-86439: Feature minimum order amount notice issue #13039

parents 3c3fd3be da4e4229
No related merge requests found
......@@ -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 = 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);
}
/**
......@@ -50,13 +60,11 @@ class ValidationMessage
\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
......
......@@ -26,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->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
);
}
......@@ -46,8 +54,6 @@ class ValidationMessageTest extends \PHPUnit\Framework\TestCase
{
$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)
......@@ -58,27 +64,13 @@ class ValidationMessageTest extends \PHPUnit\Framework\TestCase
->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);
$this->priceHelperMock->expects($this->once())
->method('currency')
->with($minimumAmount, true, false)
->will($this->returnValue($minimumAmountCurrency));
$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->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';
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment