Skip to content

Commit afafc3c

Browse files
committed
8601: Can bypass Minimum Order Amount Logic
1 parent 276c690 commit afafc3c

File tree

2 files changed

+89
-6
lines changed

2 files changed

+89
-6
lines changed

app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,13 +817,21 @@ public function reset()
817817
*/
818818
public function validateMinimumAmount()
819819
{
820-
return !($this->_scopeConfig->isSetFlag(
820+
$minimumOrderActive = $this->_scopeConfig->isSetFlag(
821821
'sales/minimum_order/active',
822822
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
823-
) && $this->_scopeConfig->isSetFlag(
823+
);
824+
825+
if ($this->_scopeConfig->isSetFlag(
824826
'sales/minimum_order/multi_address',
825-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
826-
) && !$this->getQuote()->validateMinimumAmount());
827+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE)
828+
) {
829+
$result = !($minimumOrderActive && !$this->getQuote()->validateMinimumAmount());
830+
} else {
831+
$result = !($minimumOrderActive && !$this->validateMinimumAmountForAddressItems());
832+
}
833+
834+
return $result;
827835
}
828836

829837
/**
@@ -1031,4 +1039,41 @@ private function getShippingAssignmentProcessor()
10311039
}
10321040
return $this->shippingAssignmentProcessor;
10331041
}
1042+
1043+
/**
1044+
* Validate minimum amount for "Checkout with Multiple Addresses" when
1045+
* "Validate Each Address Separately in Multi-address Checkout" is No.
1046+
*
1047+
* @return bool
1048+
*/
1049+
private function validateMinimumAmountForAddressItems()
1050+
{
1051+
$result = true;
1052+
$storeId = $this->getQuote()->getStoreId();
1053+
1054+
$minAmount = $this->_scopeConfig->getValue(
1055+
'sales/minimum_order/amount',
1056+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
1057+
$storeId
1058+
);
1059+
$taxInclude = $this->_scopeConfig->getValue(
1060+
'sales/minimum_order/tax_including',
1061+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
1062+
$storeId
1063+
);
1064+
1065+
$addresses = $this->getQuote()->getAllAddresses();
1066+
1067+
$baseTotal = 0;
1068+
foreach ($addresses as $address) {
1069+
$taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
1070+
$baseTotal += $address->getBaseSubtotalWithDiscount() + $taxes;
1071+
}
1072+
1073+
if ($baseTotal < $minAmount) {
1074+
$result = false;
1075+
}
1076+
1077+
return $result;
1078+
}
10341079
}

app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,18 @@ class MultishippingTest extends \PHPUnit\Framework\TestCase
118118
*/
119119
private $quoteRepositoryMock;
120120

121+
/**
122+
* @var PHPUnit_Framework_MockObject_MockObject
123+
*/
124+
private $scopeConfigMock;
125+
121126
protected function setUp()
122127
{
123128
$this->checkoutSessionMock = $this->createSimpleMock(Session::class);
124129
$this->customerSessionMock = $this->createSimpleMock(CustomerSession::class);
125130
$orderFactoryMock = $this->createSimpleMock(OrderFactory::class);
126131
$eventManagerMock = $this->createSimpleMock(ManagerInterface::class);
127-
$scopeConfigMock = $this->createSimpleMock(ScopeConfigInterface::class);
132+
$this->scopeConfigMock = $this->createSimpleMock(ScopeConfigInterface::class);
128133
$sessionMock = $this->createSimpleMock(Generic::class);
129134
$addressFactoryMock = $this->createSimpleMock(AddressFactory::class);
130135
$toOrderMock = $this->createSimpleMock(ToOrder::class);
@@ -166,7 +171,7 @@ protected function setUp()
166171
$orderFactoryMock,
167172
$this->addressRepositoryMock,
168173
$eventManagerMock,
169-
$scopeConfigMock,
174+
$this->scopeConfigMock,
170175
$sessionMock,
171176
$addressFactoryMock,
172177
$toOrderMock,
@@ -497,4 +502,37 @@ private function createSimpleMock($className)
497502
->disableOriginalConstructor()
498503
->getMock();
499504
}
505+
506+
public function testValidateMinimumAmountMultiAddressTrue()
507+
{
508+
$this->scopeConfigMock->expects($this->exactly(2))->method('isSetFlag')->withConsecutive(
509+
['sales/minimum_order/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE],
510+
['sales/minimum_order/multi_address', \Magento\Store\Model\ScopeInterface::SCOPE_STORE]
511+
)->willReturnOnConsecutiveCalls(true, true);
512+
513+
$this->checkoutSessionMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($this->quoteMock);
514+
$this->quoteMock->expects($this->once())->method('validateMinimumAmount')->willReturn(false);
515+
$this->assertFalse($this->model->validateMinimumAmount());
516+
}
517+
518+
public function testValidateMinimumAmountMultiAddressFalse()
519+
{
520+
$addressMock = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
521+
$this->scopeConfigMock->expects($this->exactly(2))->method('isSetFlag')->withConsecutive(
522+
['sales/minimum_order/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE],
523+
['sales/minimum_order/multi_address', \Magento\Store\Model\ScopeInterface::SCOPE_STORE]
524+
)->willReturnOnConsecutiveCalls(true, false);
525+
526+
$this->scopeConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive(
527+
['sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE],
528+
['sales/minimum_order/tax_including', \Magento\Store\Model\ScopeInterface::SCOPE_STORE]
529+
)->willReturnOnConsecutiveCalls(100, false);
530+
531+
$this->checkoutSessionMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($this->quoteMock);
532+
$this->quoteMock->expects($this->once())->method('getStoreId')->willReturn(1);
533+
$this->quoteMock->expects($this->once())->method('getAllAddresses')->willReturn([$addressMock]);
534+
$addressMock->expects($this->once())->method('getBaseSubtotalWithDiscount')->willReturn(101);
535+
536+
$this->assertTrue($this->model->validateMinimumAmount());
537+
}
500538
}

0 commit comments

Comments
 (0)