|
8 | 8 | namespace Magento\Quote\Model;
|
9 | 9 |
|
10 | 10 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
| 11 | +use Magento\Checkout\Model\Session as CheckoutSession; |
11 | 12 | use Magento\Customer\Api\CustomerRepositoryInterface;
|
12 | 13 | use Magento\Customer\Api\Data\CustomerInterface;
|
13 | 14 | use Magento\Customer\Api\Data\CustomerInterfaceFactory;
|
@@ -761,4 +762,46 @@ public function testValidateMinimumAmountWithPriceInclTaxAndDiscount()
|
761 | 762 | $this->assertEquals(5, $quote->getShippingAddress()->getBaseGrandTotal());
|
762 | 763 | $this->assertTrue($quote->validateMinimumAmount());
|
763 | 764 | }
|
| 765 | + |
| 766 | + /** |
| 767 | + * @magentoConfigFixture current_store multishipping/options/checkout_multiple 1 |
| 768 | + * @magentoAppIsolation enabled |
| 769 | + * @magentoDbIsolation enabled |
| 770 | + * @magentoDataFixture Magento/Multishipping/Fixtures/quote_with_split_items.php |
| 771 | + * @return void |
| 772 | + */ |
| 773 | + public function testIsMultiShippingModeEnabledAfterQuoteItemRemoved(): void |
| 774 | + { |
| 775 | + $quote = $this->getQuoteByReservedOrderId->execute('multishipping_quote_id'); |
| 776 | + /** @var CheckoutSession $session */ |
| 777 | + $session = $this->objectManager->get(CheckoutSession::class); |
| 778 | + $session->replaceQuote($quote); |
| 779 | + $items = $quote->getAllItems(); |
| 780 | + $idToDelete = null; |
| 781 | + foreach($items as $item) { |
| 782 | + if (!$item->getProduct()->isVirtual() && $item->getQty() == 1) { |
| 783 | + $idToDelete = $item->getId(); |
| 784 | + } |
| 785 | + } |
| 786 | + |
| 787 | + if (!is_null($idToDelete)) { |
| 788 | + $quoteShippingAddresses = $quote->getAllShippingAddresses(); |
| 789 | + foreach($quoteShippingAddresses as $shippingAddress) { |
| 790 | + if ($shippingAddress->getItemById($idToDelete)) { |
| 791 | + $shippingAddress->removeItem($idToDelete); |
| 792 | + $shippingAddress->setCollectShippingRates(true); |
| 793 | + |
| 794 | + if (count($shippingAddress->getAllItems()) == 0) { |
| 795 | + $shippingAddress->isDeleted(true); |
| 796 | + } |
| 797 | + } |
| 798 | + } |
| 799 | + $quote->removeItem($idToDelete); |
| 800 | + $this->assertEquals(1, $quote->getIsMultiShipping(), |
| 801 | + "Multi-shipping mode is disabled after quote item removal"); |
| 802 | + } else { |
| 803 | + $this->assertTrue(!is_null($idToDelete), |
| 804 | + "No Simple Product item with qty 1 to delete exists"); |
| 805 | + } |
| 806 | + } |
764 | 807 | }
|
0 commit comments