|
10 | 10 | use Magento\Directory\Model\AllowedCountries;
|
11 | 11 | use Magento\Framework\Api\AttributeValueFactory;
|
12 | 12 | use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
|
| 13 | +use Magento\Framework\App\ObjectManager; |
13 | 14 | use Magento\Framework\Exception\NoSuchEntityException;
|
14 | 15 | use Magento\Framework\Model\AbstractExtensibleModel;
|
15 | 16 | use Magento\Quote\Api\Data\PaymentInterface;
|
16 | 17 | use Magento\Quote\Model\Quote\Address;
|
17 | 18 | use Magento\Quote\Model\Quote\Address\Total as AddressTotal;
|
18 | 19 | use Magento\Sales\Model\Status;
|
19 | 20 | use Magento\Store\Model\ScopeInterface;
|
20 |
| -use Magento\Framework\App\ObjectManager; |
21 | 21 |
|
22 | 22 | /**
|
23 | 23 | * Quote model
|
@@ -2541,6 +2541,12 @@ public function getShippingAddressesItems()
|
2541 | 2541 | continue;
|
2542 | 2542 | }
|
2543 | 2543 | 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 | + |
2544 | 2550 | for ($itemIndex = 0, $itemQty = $item->getQty(); $itemIndex < $itemQty; $itemIndex++) {
|
2545 | 2551 | if ($itemIndex == 0) {
|
2546 | 2552 | $addressItem = $item;
|
@@ -2658,4 +2664,33 @@ private function assignAddress(Address $address, bool $isBillingAddress = true):
|
2658 | 2664 | : $this->setShippingAddress($address);
|
2659 | 2665 | }
|
2660 | 2666 | }
|
| 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 | + } |
2661 | 2696 | }
|
0 commit comments