Skip to content

Commit dbd2620

Browse files
committed
ACP2E-693: Addresses disappear from multi-shipping checkout after removing several items.
1 parent 1f69f02 commit dbd2620

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

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

Lines changed: 36 additions & 1 deletion
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
@@ -2541,6 +2541,12 @@ public function getShippingAddressesItems()
25412541
continue;
25422542
}
25432543
if ($item->getQty() > 1) {
2544+
//DB table `quote_item` qty value can not be set to 1, if having more than 1 child references
2545+
//in table `quote_address_item`.
2546+
if (count($this->getQuoteShippingAddressItemsByQuoteItemId($item->getItemId())) > 1) {
2547+
continue;
2548+
}
2549+
25442550
for ($itemIndex = 0, $itemQty = $item->getQty(); $itemIndex < $itemQty; $itemIndex++) {
25452551
if ($itemIndex == 0) {
25462552
$addressItem = $item;
@@ -2658,4 +2664,33 @@ private function assignAddress(Address $address, bool $isBillingAddress = true):
26582664
: $this->setShippingAddress($address);
26592665
}
26602666
}
2667+
2668+
/**
2669+
* Returns quote address items
2670+
*
2671+
* @param $itemId
2672+
* @return array
2673+
*/
2674+
private function getQuoteShippingAddressItemsByQuoteItemId($itemId = null): array
2675+
{
2676+
$addressItems = [];
2677+
if ($itemId !== null && $this->isMultipleShippingAddresses()) {
2678+
$addresses = $this->getAllShippingAddresses();
2679+
foreach ($addresses as $address) {
2680+
foreach ($address->getAllItems() as $item) {
2681+
if ($item->getParentItemId()) {
2682+
continue;
2683+
}
2684+
if ($item->getProduct()->getIsVirtual()) {
2685+
continue;
2686+
}
2687+
if ($item->getQuoteItemId() === $itemId) {
2688+
$addressItems[] = $item;
2689+
}
2690+
}
2691+
}
2692+
}
2693+
2694+
return $addressItems;
2695+
}
26612696
}

0 commit comments

Comments
 (0)