Skip to content

Feature minimum order amount notice issue #13039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 10, 2018
Merged
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,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);
}

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,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->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 @@ -58,27 +64,13 @@ 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);
$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';
Expand Down