Skip to content

[Backport] 2.2 develop pr port 19136 #20641

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

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
14 changes: 12 additions & 2 deletions app/code/Magento/Quote/Model/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,11 @@ public function validateMinimumAmount($multishipping = false)
if (!$minOrderActive) {
return true;
}
$includeDiscount = $this->_scopeConfig->getValue(
'sales/minimum_order/include_discount_amount',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);
$minOrderMulti = $this->_scopeConfig->isSetFlag(
'sales/minimum_order/multi_address',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
Expand Down Expand Up @@ -2251,7 +2256,10 @@ public function validateMinimumAmount($multishipping = false)
$taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
foreach ($address->getQuote()->getItemsCollection() as $item) {
/** @var \Magento\Quote\Model\Quote\Item $item */
$amount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $taxes;
$amount = $includeDiscount ?
$item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $taxes :
$item->getBaseRowTotal() + $taxes;

if ($amount < $minAmount) {
return false;
}
Expand All @@ -2261,7 +2269,9 @@ public function validateMinimumAmount($multishipping = false)
$baseTotal = 0;
foreach ($addresses as $address) {
$taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
$baseTotal += $address->getBaseSubtotalWithDiscount() + $taxes;
$baseTotal += $includeDiscount ?
$address->getBaseSubtotalWithDiscount() + $taxes :
$address->getBaseSubtotal() + $taxes;
}
if ($baseTotal < $minAmount) {
return false;
Expand Down
10 changes: 9 additions & 1 deletion app/code/Magento/Quote/Model/Quote/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,11 @@ public function validateMinimumAmount()
return true;
}

$includeDiscount = $this->_scopeConfig->getValue(
'sales/minimum_order/include_discount_amount',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);
$amount = $this->_scopeConfig->getValue(
'sales/minimum_order/amount',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
Expand All @@ -1160,9 +1165,12 @@ public function validateMinimumAmount()
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);

$taxes = $taxInclude ? $this->getBaseTaxAmount() : 0;

return ($this->getBaseSubtotalWithDiscount() + $taxes >= $amount);
return $includeDiscount ?
($this->getBaseSubtotalWithDiscount() + $taxes >= $amount) :
($this->getBaseSubtotal() + $taxes >= $amount);
}

/**
Expand Down
27 changes: 27 additions & 0 deletions app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public function testValidateMiniumumAmountVirtual()
$scopeConfigValues = [
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];

Expand All @@ -240,6 +241,31 @@ public function testValidateMiniumumAmount()
$scopeConfigValues = [
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];

$this->quote->expects($this->once())
->method('getStoreId')
->willReturn($storeId);
$this->quote->expects($this->once())
->method('getIsVirtual')
->willReturn(false);

$this->scopeConfig->expects($this->once())
->method('isSetFlag')
->willReturnMap($scopeConfigValues);

$this->assertTrue($this->address->validateMinimumAmount());
}

public function testValidateMiniumumAmountWithoutDiscount()
{
$storeId = 1;
$scopeConfigValues = [
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, false],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];

Expand All @@ -263,6 +289,7 @@ public function testValidateMiniumumAmountNegative()
$scopeConfigValues = [
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];

Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ public function testValidateMiniumumAmount()
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];
$this->scopeConfig->expects($this->any())
Expand All @@ -977,6 +978,7 @@ public function testValidateMiniumumAmountNegative()
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];
$this->scopeConfig->expects($this->any())
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Sales/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
<label>Minimum Amount</label>
<comment>Subtotal after discount</comment>
</field>
<field id="include_discount_amount" translate="label" sortOrder="12" type="select" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
<label>Include Discount Amount</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Choosing yes will be used subtotal after discount, otherwise only subtotal will be used</comment>
</field>
<field id="tax_including" translate="label" sortOrder="15" type="select" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
<label>Include Tax to Amount</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Sales/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<allow_zero_grandtotal>1</allow_zero_grandtotal>
</zerograndtotal_creditmemo>
<minimum_order>
<include_discount_amount>1</include_discount_amount>
<tax_including>1</tax_including>
</minimum_order>
<orders>
Expand Down