Skip to content

Commit a29dbc0

Browse files
author
Joan He
committed
Merge remote-tracking branch 'owls/MAGETWO-94308-multiship-min-order' into BugFixPR
2 parents c1ab6db + ef40954 commit a29dbc0

File tree

3 files changed

+100
-17
lines changed

3 files changed

+100
-17
lines changed

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

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ private function logExceptions(array $exceptionList)
876876
*/
877877
public function save()
878878
{
879-
$this->getQuote()->collectTotals();
879+
$this->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
880880
$this->quoteRepository->save($this->getQuote());
881881
return $this;
882882
}
@@ -899,13 +899,23 @@ public function reset()
899899
*/
900900
public function validateMinimumAmount()
901901
{
902-
return !($this->_scopeConfig->isSetFlag(
902+
$minimumOrderActive = $this->_scopeConfig->isSetFlag(
903903
'sales/minimum_order/active',
904904
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
905-
) && $this->_scopeConfig->isSetFlag(
905+
);
906+
907+
$minimumOrderMultiFlag = $this->_scopeConfig->isSetFlag(
906908
'sales/minimum_order/multi_address',
907909
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
908-
) && !$this->getQuote()->validateMinimumAmount());
910+
);
911+
912+
if ($minimumOrderMultiFlag) {
913+
$result = !($minimumOrderActive && !$this->getQuote()->validateMinimumAmount());
914+
} else {
915+
$result = !($minimumOrderActive && !$this->validateMinimumAmountForAddressItems());
916+
}
917+
918+
return $result;
909919
}
910920

911921
/**
@@ -1123,6 +1133,44 @@ private function getShippingAssignmentProcessor()
11231133
return $this->shippingAssignmentProcessor;
11241134
}
11251135

1136+
/**
1137+
* Validate minimum amount for "Checkout with Multiple Addresses" when
1138+
* "Validate Each Address Separately in Multi-address Checkout" is No.
1139+
*
1140+
* @return bool
1141+
*/
1142+
private function validateMinimumAmountForAddressItems()
1143+
{
1144+
$result = true;
1145+
$storeId = $this->getQuote()->getStoreId();
1146+
1147+
$minAmount = $this->_scopeConfig->getValue(
1148+
'sales/minimum_order/amount',
1149+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
1150+
$storeId
1151+
);
1152+
$taxInclude = $this->_scopeConfig->getValue(
1153+
'sales/minimum_order/tax_including',
1154+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
1155+
$storeId
1156+
);
1157+
1158+
$this->getQuote()->collectTotals();
1159+
$addresses = $this->getQuote()->getAllAddresses();
1160+
1161+
$baseTotal = 0;
1162+
foreach ($addresses as $address) {
1163+
$taxes = $taxInclude ? $address->getBaseTaxAmount() : 0;
1164+
$baseTotal += $address->getBaseSubtotalWithDiscount() + $taxes;
1165+
}
1166+
1167+
if ($baseTotal < $minAmount) {
1168+
$result = false;
1169+
}
1170+
1171+
return $result;
1172+
}
1173+
11261174
/**
11271175
* Remove successfully placed items from quote.
11281176
*

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

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,18 @@ class MultishippingTest extends \PHPUnit\Framework\TestCase
167167
*/
168168
private $sessionMock;
169169

170+
/**
171+
* @var PHPUnit_Framework_MockObject_MockObject
172+
*/
173+
private $scopeConfigMock;
174+
170175
protected function setUp()
171176
{
172177
$this->checkoutSessionMock = $this->createSimpleMock(Session::class);
173178
$this->customerSessionMock = $this->createSimpleMock(CustomerSession::class);
174179
$this->orderFactoryMock = $this->createSimpleMock(OrderFactory::class);
175180
$eventManagerMock = $this->createSimpleMock(ManagerInterface::class);
176-
$scopeConfigMock = $this->createSimpleMock(ScopeConfigInterface::class);
181+
$this->scopeConfigMock = $this->createSimpleMock(ScopeConfigInterface::class);
177182
$this->sessionMock = $this->createSimpleMock(Generic::class);
178183
$addressFactoryMock = $this->createSimpleMock(AddressFactory::class);
179184
$this->toOrderMock = $this->createSimpleMock(ToOrder::class);
@@ -224,7 +229,7 @@ protected function setUp()
224229
$this->orderFactoryMock,
225230
$this->addressRepositoryMock,
226231
$eventManagerMock,
227-
$scopeConfigMock,
232+
$this->scopeConfigMock,
228233
$this->sessionMock,
229234
$addressFactoryMock,
230235
$this->toOrderMock,
@@ -277,6 +282,10 @@ public function testSetShippingItemsInformation()
277282
->willReturn(null);
278283

279284
$this->quoteMock->expects($this->atLeastOnce())->method('getAllItems')->willReturn([]);
285+
$this->quoteMock->expects($this->once())
286+
->method('__call')
287+
->with('setTotalsCollectedFlag', [false])
288+
->willReturnSelf();
280289

281290
$this->filterBuilderMock->expects($this->atLeastOnce())->method('setField')->willReturnSelf();
282291
$this->filterBuilderMock->expects($this->atLeastOnce())->method('setValue')->willReturnSelf();
@@ -416,6 +425,10 @@ public function testSetShippingMethods()
416425
$addressMock->expects($this->once())->method('getId')->willReturn($addressId);
417426
$this->quoteMock->expects($this->once())->method('getAllShippingAddresses')->willReturn([$addressMock]);
418427
$addressMock->expects($this->once())->method('setShippingMethod')->with($methodsArray[$addressId]);
428+
$this->quoteMock->expects($this->once())
429+
->method('__call')
430+
->with('setTotalsCollectedFlag', [false])
431+
->willReturnSelf();
419432

420433
$this->mockShippingAssignment();
421434

@@ -809,4 +822,37 @@ private function createSimpleMock($className)
809822
->disableOriginalConstructor()
810823
->getMock();
811824
}
825+
826+
public function testValidateMinimumAmountMultiAddressTrue()
827+
{
828+
$this->scopeConfigMock->expects($this->exactly(2))->method('isSetFlag')->withConsecutive(
829+
['sales/minimum_order/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE],
830+
['sales/minimum_order/multi_address', \Magento\Store\Model\ScopeInterface::SCOPE_STORE]
831+
)->willReturnOnConsecutiveCalls(true, true);
832+
833+
$this->checkoutSessionMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($this->quoteMock);
834+
$this->quoteMock->expects($this->once())->method('validateMinimumAmount')->willReturn(false);
835+
$this->assertFalse($this->model->validateMinimumAmount());
836+
}
837+
838+
public function testValidateMinimumAmountMultiAddressFalse()
839+
{
840+
$addressMock = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
841+
$this->scopeConfigMock->expects($this->exactly(2))->method('isSetFlag')->withConsecutive(
842+
['sales/minimum_order/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE],
843+
['sales/minimum_order/multi_address', \Magento\Store\Model\ScopeInterface::SCOPE_STORE]
844+
)->willReturnOnConsecutiveCalls(true, false);
845+
846+
$this->scopeConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive(
847+
['sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE],
848+
['sales/minimum_order/tax_including', \Magento\Store\Model\ScopeInterface::SCOPE_STORE]
849+
)->willReturnOnConsecutiveCalls(100, false);
850+
851+
$this->checkoutSessionMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($this->quoteMock);
852+
$this->quoteMock->expects($this->once())->method('getStoreId')->willReturn(1);
853+
$this->quoteMock->expects($this->once())->method('getAllAddresses')->willReturn([$addressMock]);
854+
$addressMock->expects($this->once())->method('getBaseSubtotalWithDiscount')->willReturn(101);
855+
856+
$this->assertTrue($this->model->validateMinimumAmount());
857+
}
812858
}

app/code/Magento/Multishipping/view/frontend/templates/checkout/addresses.phtml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@
1414
* @var $block \Magento\Multishipping\Block\Checkout\Addresses
1515
*/
1616
?>
17-
<form id="checkout_multishipping_form"
18-
data-mage-init='{
19-
"multiShipping":{},
20-
"validation":{},
21-
"cartUpdate": {
22-
"validationURL": "/multishipping/checkout/checkItems",
23-
"eventName": "updateMulticartItemQty"
24-
}}'
25-
action="<?= $block->escapeUrl($block->getPostActionUrl()) ?>"
26-
method="post"
27-
class="multicheckout address form">
2817
<form id="checkout_multishipping_form"
2918
data-mage-init='{
3019
"multiShipping":{},

0 commit comments

Comments
 (0)