Skip to content

Commit 2ba5836

Browse files
committed
Merge remote-tracking branch 'origin/MC-38825' into 2.4-develop-pr46
2 parents 9337fad + e5a7950 commit 2ba5836

File tree

3 files changed

+125
-15
lines changed

3 files changed

+125
-15
lines changed

app/code/Magento/Multishipping/Model/Cart/Controller/CartPlugin.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\App\RequestInterface;
1414
use Magento\Framework\Exception\LocalizedException;
1515
use Magento\Multishipping\Model\Checkout\Type\Multishipping\State;
16+
use Magento\Multishipping\Model\DisableMultishipping;
1617
use Magento\Quote\Api\CartRepositoryInterface;
1718
use Magento\Quote\Model\Quote;
1819

@@ -36,19 +37,27 @@ class CartPlugin
3637
*/
3738
private $addressRepository;
3839

40+
/**
41+
* @var DisableMultishipping
42+
*/
43+
private $disableMultishipping;
44+
3945
/**
4046
* @param CartRepositoryInterface $cartRepository
4147
* @param Session $checkoutSession
4248
* @param AddressRepositoryInterface $addressRepository
49+
* @param DisableMultishipping $disableMultishipping
4350
*/
4451
public function __construct(
4552
CartRepositoryInterface $cartRepository,
4653
Session $checkoutSession,
47-
AddressRepositoryInterface $addressRepository
54+
AddressRepositoryInterface $addressRepository,
55+
DisableMultishipping $disableMultishipping
4856
) {
4957
$this->cartRepository = $cartRepository;
5058
$this->checkoutSession = $checkoutSession;
5159
$this->addressRepository = $addressRepository;
60+
$this->disableMultishipping = $disableMultishipping;
5261
}
5362

5463
/**
@@ -76,6 +85,9 @@ public function beforeDispatch(Cart $subject, RequestInterface $request)
7685
$shippingAddress->importCustomerAddressData($defaultCustomerAddress);
7786
}
7887
$this->cartRepository->save($quote);
88+
} elseif ($this->disableMultishipping->execute($quote) && $this->isVirtualItemInQuote($quote)) {
89+
$quote->setTotalsCollectedFlag(false);
90+
$this->cartRepository->save($quote);
7991
}
8092
}
8193

@@ -88,4 +100,24 @@ private function isCheckoutComplete() : bool
88100
{
89101
return (bool) ($this->checkoutSession->getStepData(State::STEP_SHIPPING)['is_complete'] ?? true);
90102
}
103+
104+
/**
105+
* Checks whether quote has virtual items
106+
*
107+
* @param Quote $quote
108+
* @return bool
109+
*/
110+
private function isVirtualItemInQuote(Quote $quote): bool
111+
{
112+
$items = $quote->getItems();
113+
if (!empty($items)) {
114+
foreach ($items as $item) {
115+
if ($item->getIsVirtual()) {
116+
return true;
117+
}
118+
}
119+
}
120+
121+
return false;
122+
}
91123
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontDisableMultishippingModeCheckoutOnBackToCartTest">
12+
<annotations>
13+
<features value="Multishipping"/>
14+
<stories value="Multishipping"/>
15+
<title value="Disable multishipping checkout on backing to cart"/>
16+
<description value="Cart page summary block should count virtual product price after backing back to the cart from multishipping checkout."/>
17+
<severity value="CRITICAL"/>
18+
<testCaseId value="MC-39007"/>
19+
<useCaseId value="MC-38825"/>
20+
<group value="multishipping"/>
21+
</annotations>
22+
<before>
23+
<createData entity="ApiCategory" stepKey="createCategory"/>
24+
<createData entity="_defaultProduct" stepKey="createSimpleProduct">
25+
<requiredEntity createDataKey="createCategory"/>
26+
</createData>
27+
<createData entity="VirtualProduct" stepKey="createVirtualProduct">
28+
<requiredEntity createDataKey="createCategory"/>
29+
</createData>
30+
<createData entity="Simple_US_Customer_Multiple_Addresses" stepKey="createCustomerWithMultipleAddresses"/>
31+
</before>
32+
<after>
33+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
34+
<deleteData createDataKey="createVirtualProduct" stepKey="deleteVirtualProduct"/>
35+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
36+
<deleteData createDataKey="createCustomerWithMultipleAddresses" stepKey="deleteCustomer"/>
37+
</after>
38+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginAsCustomer">
39+
<argument name="Customer" value="$createCustomerWithMultipleAddresses$"/>
40+
</actionGroup>
41+
42+
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openVirtualProductPage">
43+
<argument name="product" value="$createVirtualProduct$"/>
44+
</actionGroup>
45+
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addVirtualProductToCart">
46+
<argument name="product" value="$createVirtualProduct$"/>
47+
<argument name="productCount" value="1"/>
48+
</actionGroup>
49+
50+
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openSimpleProductPage">
51+
<argument name="product" value="$createSimpleProduct$"/>
52+
</actionGroup>
53+
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addSimpleProductToCart">
54+
<argument name="product" value="$createSimpleProduct$"/>
55+
<argument name="productCount" value="2"/>
56+
</actionGroup>
57+
58+
<actionGroup ref="ClickViewAndEditCartFromMiniCartActionGroup" stepKey="goToShoppingCartFromMinicart"/>
59+
<grabTextFrom selector="{{CheckoutPaymentSection.orderSummaryTotal}}" stepKey="grabTotal"/>
60+
61+
<actionGroup ref="StorefrontGoCheckoutWithMultipleAddressesActionGroup" stepKey="goCheckoutWithMultipleAddresses"/>
62+
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="goBackToShoppingCartPage"/>
63+
<actionGroup ref="AssertStorefrontCheckoutPaymentSummaryTotalActionGroup" stepKey="assertSummaryTotal">
64+
<argument name="orderTotal" value="{$grabTotal}"/>
65+
</actionGroup>
66+
</test>
67+
</tests>

app/code/Magento/Multishipping/Test/Unit/Model/Cart/Controller/CartPluginTest.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Customer\Api\Data\CustomerInterface;
1515
use Magento\Framework\App\RequestInterface;
1616
use Magento\Multishipping\Model\Cart\Controller\CartPlugin;
17+
use Magento\Multishipping\Model\DisableMultishipping;
1718
use Magento\Quote\Api\CartRepositoryInterface;
1819
use Magento\Quote\Model\Quote;
1920
use Magento\Quote\Model\Quote\Address;
@@ -47,10 +48,12 @@ protected function setUp(): void
4748
$this->cartRepositoryMock = $this->getMockForAbstractClass(CartRepositoryInterface::class);
4849
$this->checkoutSessionMock = $this->createMock(Session::class);
4950
$this->addressRepositoryMock = $this->getMockForAbstractClass(AddressRepositoryInterface::class);
51+
$disableMultishippingMock = $this->createMock(DisableMultishipping::class);
5052
$this->model = new CartPlugin(
5153
$this->cartRepositoryMock,
5254
$this->checkoutSessionMock,
53-
$this->addressRepositoryMock
55+
$this->addressRepositoryMock,
56+
$disableMultishippingMock
5457
);
5558
}
5659

@@ -65,33 +68,41 @@ public function testBeforeDispatch()
6568
'getShippingAddress',
6669
'getCustomer'
6770
]);
68-
$this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($quoteMock);
71+
$this->checkoutSessionMock->method('getQuote')
72+
->willReturn($quoteMock);
6973

7074
$addressMock = $this->createMock(Address::class);
71-
$addressMock->expects($this->once())->method('getId')->willReturn($addressId);
75+
$addressMock->method('getId')
76+
->willReturn($addressId);
7277

73-
$quoteMock->expects($this->once())->method('isMultipleShippingAddresses')->willReturn(true);
74-
$quoteMock->expects($this->once())->method('getAllShippingAddresses')->willReturn([$addressMock]);
75-
$quoteMock->expects($this->once())->method('removeAddress')->with($addressId)->willReturnSelf();
78+
$quoteMock->method('isMultipleShippingAddresses')
79+
->willReturn(true);
80+
$quoteMock->method('getAllShippingAddresses')
81+
->willReturn([$addressMock]);
82+
$quoteMock->method('removeAddress')
83+
->with($addressId)->willReturnSelf();
7684

7785
$shippingAddressMock = $this->createMock(Address::class);
78-
$quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($shippingAddressMock);
86+
$quoteMock->method('getShippingAddress')
87+
->willReturn($shippingAddressMock);
7988
$customerMock = $this->getMockForAbstractClass(CustomerInterface::class);
80-
$quoteMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
81-
$customerMock->expects($this->once())->method('getDefaultShipping')->willReturn($customerAddressId);
89+
$quoteMock->method('getCustomer')
90+
->willReturn($customerMock);
91+
$customerMock->method('getDefaultShipping')
92+
->willReturn($customerAddressId);
8293

8394
$customerAddressMock = $this->getMockForAbstractClass(AddressInterface::class);
84-
$this->addressRepositoryMock->expects($this->once())
85-
->method('getById')
95+
$this->addressRepositoryMock->method('getById')
8696
->with($customerAddressId)
8797
->willReturn($customerAddressMock);
8898

89-
$shippingAddressMock->expects($this->once())
90-
->method('importCustomerAddressData')
99+
$shippingAddressMock->method('importCustomerAddressData')
91100
->with($customerAddressMock)
92101
->willReturnSelf();
93102

94-
$this->cartRepositoryMock->expects($this->once())->method('save')->with($quoteMock);
103+
$this->cartRepositoryMock->expects($this->once())
104+
->method('save')
105+
->with($quoteMock);
95106

96107
$this->model->beforeDispatch(
97108
$this->createMock(Cart::class),

0 commit comments

Comments
 (0)