Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -48,16 +60,13 @@ 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);
}

return $message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function _construct()
*/
public function getStoreId()
{
return (int)$this->_quote->getStoreId();
return (int)$this->_productCollectionFactory->create()->getStoreId();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Quote\Test\Unit\Model\Quote\Validator\MinimumOrderAmount;

use Magento\Framework\Phrase;

class ValidationMessageTest extends \PHPUnit_Framework_TestCase
{
/**
Expand All @@ -24,28 +26,34 @@ 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
);
}

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)
Expand All @@ -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';
Expand All @@ -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());
}
}