Skip to content

Commit cf4dc42

Browse files
ENGCOM-3914: [Up-port 2.3] Added option to exclude discount for minimum order amount calculation #19136
- Merge Pull Request #19136 from ccasciotti/magento2:up-port-pull-18524 - Merged commits: 1. 77d2a6c 2. 8d4e4a2
2 parents e5c1527 + 8d4e4a2 commit cf4dc42

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

app/code/Magento/Quote/Model/Quote.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,11 @@ public function validateMinimumAmount($multishipping = false)
22462246
if (!$minOrderActive) {
22472247
return true;
22482248
}
2249+
$includeDiscount = $this->_scopeConfig->getValue(
2250+
'sales/minimum_order/include_discount_amount',
2251+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
2252+
$storeId
2253+
);
22492254
$minOrderMulti = $this->_scopeConfig->isSetFlag(
22502255
'sales/minimum_order/multi_address',
22512256
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
@@ -2279,7 +2284,10 @@ public function validateMinimumAmount($multishipping = false)
22792284
$taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
22802285
foreach ($address->getQuote()->getItemsCollection() as $item) {
22812286
/** @var \Magento\Quote\Model\Quote\Item $item */
2282-
$amount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $taxes;
2287+
$amount = $includeDiscount ?
2288+
$item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $taxes :
2289+
$item->getBaseRowTotal() + $taxes;
2290+
22832291
if ($amount < $minAmount) {
22842292
return false;
22852293
}
@@ -2289,7 +2297,9 @@ public function validateMinimumAmount($multishipping = false)
22892297
$baseTotal = 0;
22902298
foreach ($addresses as $address) {
22912299
$taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
2292-
$baseTotal += $address->getBaseSubtotalWithDiscount() + $taxes;
2300+
$baseTotal += $includeDiscount ?
2301+
$address->getBaseSubtotalWithDiscount() + $taxes :
2302+
$address->getBaseSubtotal() + $taxes;
22932303
}
22942304
if ($baseTotal < $minAmount) {
22952305
return false;

app/code/Magento/Quote/Model/Quote/Address.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,11 @@ public function validateMinimumAmount()
11491149
return true;
11501150
}
11511151

1152+
$includeDiscount = $this->_scopeConfig->getValue(
1153+
'sales/minimum_order/include_discount_amount',
1154+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
1155+
$storeId
1156+
);
11521157
$amount = $this->_scopeConfig->getValue(
11531158
'sales/minimum_order/amount',
11541159
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
@@ -1159,9 +1164,12 @@ public function validateMinimumAmount()
11591164
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
11601165
$storeId
11611166
);
1167+
11621168
$taxes = $taxInclude ? $this->getBaseTaxAmount() : 0;
11631169

1164-
return ($this->getBaseSubtotalWithDiscount() + $taxes >= $amount);
1170+
return $includeDiscount ?
1171+
($this->getBaseSubtotalWithDiscount() + $taxes >= $amount) :
1172+
($this->getBaseSubtotal() + $taxes >= $amount);
11651173
}
11661174

11671175
/**

app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public function testValidateMinimumAmountVirtual()
216216
$scopeConfigValues = [
217217
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
218218
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
219+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
219220
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
220221
];
221222

@@ -240,6 +241,31 @@ public function testValidateMinimumAmount()
240241
$scopeConfigValues = [
241242
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
242243
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
244+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
245+
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
246+
];
247+
248+
$this->quote->expects($this->once())
249+
->method('getStoreId')
250+
->willReturn($storeId);
251+
$this->quote->expects($this->once())
252+
->method('getIsVirtual')
253+
->willReturn(false);
254+
255+
$this->scopeConfig->expects($this->once())
256+
->method('isSetFlag')
257+
->willReturnMap($scopeConfigValues);
258+
259+
$this->assertTrue($this->address->validateMinimumAmount());
260+
}
261+
262+
public function testValidateMiniumumAmountWithoutDiscount()
263+
{
264+
$storeId = 1;
265+
$scopeConfigValues = [
266+
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
267+
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
268+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, false],
243269
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
244270
];
245271

@@ -263,6 +289,7 @@ public function testValidateMinimumAmountNegative()
263289
$scopeConfigValues = [
264290
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
265291
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
292+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
266293
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
267294
];
268295

app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ public function testValidateMinimumAmount()
975975
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
976976
['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true],
977977
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
978+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
978979
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
979980
];
980981
$this->scopeConfig->expects($this->any())
@@ -1001,6 +1002,7 @@ public function testValidateMinimumAmountNegative()
10011002
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
10021003
['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true],
10031004
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
1005+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
10041006
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
10051007
];
10061008
$this->scopeConfig->expects($this->any())

app/code/Magento/Sales/etc/adminhtml/system.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989
<label>Minimum Amount</label>
9090
<comment>Subtotal after discount</comment>
9191
</field>
92+
<field id="include_discount_amount" translate="label" sortOrder="12" type="select" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
93+
<label>Include Discount Amount</label>
94+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
95+
<comment>Choosing yes will be used subtotal after discount, otherwise only subtotal will be used</comment>
96+
</field>
9297
<field id="tax_including" translate="label" sortOrder="15" type="select" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
9398
<label>Include Tax to Amount</label>
9499
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>

app/code/Magento/Sales/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<allow_zero_grandtotal>1</allow_zero_grandtotal>
2323
</zerograndtotal_creditmemo>
2424
<minimum_order>
25+
<include_discount_amount>1</include_discount_amount>
2526
<tax_including>1</tax_including>
2627
</minimum_order>
2728
<orders>

0 commit comments

Comments
 (0)