Skip to content

Commit 887f99d

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-693' into PR_L3_18_04_2022
2 parents 1c9e944 + 32213d7 commit 887f99d

File tree

3 files changed

+137
-2
lines changed

3 files changed

+137
-2
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontMultiShippingSaveAddressActionGroup" extends="StorefrontSaveAddressActionGroup">
12+
<remove keyForRemoval="goToShippingInformation"/>
13+
<remove keyForRemoval="waitForShippingPageLoad"/>
14+
</actionGroup>
15+
</actionGroups>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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="StoreFrontRemoveItemFromMultishipmentCartTest">
12+
<annotations>
13+
<features value="Multishipping"/>
14+
<stories value="Remove Item one by one from Multiple Shipping with three different addresses"/>
15+
<title value="Remove Item one by one from Multiple Shipping with three different addresses"/>
16+
<description value="Remove Item one by one from Multiple Shipping with three different addresses."/>
17+
<severity value="AVERAGE"/>
18+
<testCaseId value="AC-2776"/>
19+
<useCaseId value="ACP2E-693"/>
20+
<group value="Multishipment"/>
21+
</annotations>
22+
<before>
23+
<!-- Login as Admin -->
24+
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
25+
<!-- Create simple products -->
26+
<createData entity="SimpleSubCategory" stepKey="createCategory"/>
27+
<createData entity="SimpleProduct" stepKey="firstProduct">
28+
<requiredEntity createDataKey="createCategory"/>
29+
</createData>
30+
<createData entity="Customer_US_UK_DE" stepKey="createCustomerWithMultipleAddresses"/>
31+
</before>
32+
<after>
33+
<!-- Delete created data -->
34+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
35+
<deleteData createDataKey="firstProduct" stepKey="deleteFirstProduct"/>
36+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
37+
<deleteData createDataKey="createCustomerWithMultipleAddresses" stepKey="deleteCustomer"/>
38+
</after>
39+
<!-- Login to the Storefront as created customer -->
40+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginAsCustomer">
41+
<argument name="Customer" value="$$createCustomerWithMultipleAddresses$$"/>
42+
</actionGroup>
43+
<!-- Open the simple product page -->
44+
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="goToProductPage">
45+
<argument name="productUrl" value="$$firstProduct.custom_attributes[url_key]$$"/>
46+
</actionGroup>
47+
<!-- Add to Cart three times of the product -->
48+
<actionGroup ref="AddProductWithQtyToCartFromStorefrontProductPageActionGroup" stepKey="addProductToCart">
49+
<argument name="productName" value="$$firstProduct.name$$"/>
50+
<argument name="productQty" value="3"/>
51+
</actionGroup>
52+
<!--Go to Cart -->
53+
<actionGroup ref="StorefrontOpenCartFromMinicartActionGroup" stepKey="openCartWithIdenticalProducts"/>
54+
<!--Check Out with Multiple Addresses -->
55+
<actionGroup ref="StorefrontCheckoutWithMultipleAddressesActionGroup" stepKey="checkoutWithThreeDifferentAddresses"/>
56+
<!-- Select different addresses and click 'Go to Shipping Information' -->
57+
<actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectFirstAddressFromThree">
58+
<argument name="sequenceNumber" value="1"/>
59+
<argument name="option" value="John Doe, 368 Broadway St. 113, New York, New York 10001, United States"/>
60+
</actionGroup>
61+
<actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectSecondAddressFromThree">
62+
<argument name="sequenceNumber" value="2"/>
63+
<argument name="option" value="John Doe, Augsburger Strabe 41, Berlin, 10789, Germany"/>
64+
</actionGroup>
65+
<actionGroup ref="StorefrontSelectAddressActionGroup" stepKey="selectThirdAddressFromThree">
66+
<argument name="sequenceNumber" value="3"/>
67+
<argument name="option" value="Jane Doe, 172, Westminster Bridge Rd, London, SE1 7RW, United Kingdom"/>
68+
</actionGroup>
69+
<!-- Save updated addresses -->
70+
<actionGroup ref="StorefrontMultiShippingSaveAddressActionGroup" stepKey="saveThreeDifferentAddresses"/>
71+
<!-- Verify there are 3 items available on cart page -->
72+
<seeNumberOfElements userInput="3" selector="a.action.delete" stepKey="seeThreeItems"/>
73+
<!-- Remove first simple item from cart -->
74+
<actionGroup ref="StorefrontRemoveProductOnCheckoutActionGroup" stepKey="removeFirstItemFromCart"/>
75+
<waitForPageLoad time="30" stepKey="waitForCartSummaryPageToLoadAfterRemovalOfFirstItem"/>
76+
<!-- Verify there are 2 items still available after removal of first -->
77+
<seeNumberOfElements userInput="2" selector="a.action.delete" stepKey="seeTwoItems"/>
78+
<!-- Remove second simple item from cart -->
79+
<actionGroup ref="StorefrontRemoveProductOnCheckoutActionGroup" stepKey="removeSecondItemFromCart"/>
80+
<waitForPageLoad time="30" stepKey="waitForCartSummaryPageToLoadAfterRemovalOfSecondItem"/>
81+
<!-- Verify there are 1 items still available after removal of second -->
82+
<seeNumberOfElements userInput="1" selector="a.action.delete" stepKey="seeOneItems"/>
83+
<!-- Remove third simple item from cart -->
84+
<actionGroup ref="StorefrontRemoveProductOnCheckoutActionGroup" stepKey="removeThirdItemFromCart"/>
85+
<waitForPageLoad time="30" stepKey="waitForCartSummaryPageToLoadAfterRemovalOfTestItem"/>
86+
</test>
87+
</tests>

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
use Magento\Directory\Model\AllowedCountries;
1111
use Magento\Framework\Api\AttributeValueFactory;
1212
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
13+
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\Exception\NoSuchEntityException;
1415
use Magento\Framework\Model\AbstractExtensibleModel;
1516
use Magento\Quote\Api\Data\PaymentInterface;
1617
use Magento\Quote\Model\Quote\Address;
1718
use Magento\Quote\Model\Quote\Address\Total as AddressTotal;
1819
use Magento\Sales\Model\Status;
1920
use Magento\Store\Model\ScopeInterface;
20-
use Magento\Framework\App\ObjectManager;
2121

2222
/**
2323
* Quote model
@@ -2523,6 +2523,7 @@ public function getCheckoutMethod($originalMethod = false)
25232523
* Get quote items assigned to different quote addresses populated per item qty.
25242524
*
25252525
* @return array
2526+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
25262527
*/
25272528
public function getShippingAddressesItems()
25282529
{
@@ -2541,8 +2542,14 @@ public function getShippingAddressesItems()
25412542
continue;
25422543
}
25432544
if ($item->getQty() > 1) {
2545+
//DB table `quote_item` qty value can not be set to 1, if having more than 1 child references
2546+
//in table `quote_address_item`.
2547+
if ($item->getItemId() !== null
2548+
&& count($this->getQuoteShippingAddressItemsByQuoteItemId($item->getItemId())) > 1) {
2549+
continue;
2550+
}
25442551
for ($itemIndex = 0, $itemQty = $item->getQty(); $itemIndex < $itemQty; $itemIndex++) {
2545-
if ($itemIndex == 0) {
2552+
if ($itemIndex === 0) {
25462553
$addressItem = $item;
25472554
} else {
25482555
$addressItem = clone $item;
@@ -2658,4 +2665,30 @@ private function assignAddress(Address $address, bool $isBillingAddress = true):
26582665
: $this->setShippingAddress($address);
26592666
}
26602667
}
2668+
2669+
/**
2670+
* Returns quote address items
2671+
*
2672+
* @param int $itemId
2673+
* @return array
2674+
*/
2675+
private function getQuoteShippingAddressItemsByQuoteItemId(int $itemId): array
2676+
{
2677+
$addressItems = [];
2678+
if ($this->isMultipleShippingAddresses()) {
2679+
$addresses = $this->getAllShippingAddresses();
2680+
foreach ($addresses as $address) {
2681+
foreach ($address->getAllItems() as $item) {
2682+
if ($item->getParentItemId() || $item->getProduct()->getIsVirtual()) {
2683+
continue;
2684+
}
2685+
if ((int)$item->getQuoteItemId() === $itemId) {
2686+
$addressItems[] = $item;
2687+
}
2688+
}
2689+
}
2690+
}
2691+
2692+
return $addressItems;
2693+
}
26612694
}

0 commit comments

Comments
 (0)