Skip to content

Commit 8e3b513

Browse files
committed
Merge branch 'ACP2E-94' of https://github.com/magento-l3/magento2ce into PR1-21-01-2022
2 parents cf3a156 + 894a367 commit 8e3b513

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C
112112
/**
113113
* Checkout login method key
114114
*/
115-
const CHECKOUT_METHOD_LOGIN_IN = 'login_in';
115+
public const CHECKOUT_METHOD_LOGIN_IN = 'login_in';
116116

117117
/**
118118
* @var string
@@ -172,14 +172,14 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C
172172
protected $_preventSaving = false;
173173

174174
/**
175-
* Catalog product
175+
* Product of the catalog
176176
*
177177
* @var \Magento\Catalog\Helper\Product
178178
*/
179179
protected $_catalogProduct;
180180

181181
/**
182-
* Quote validator
182+
* To perform validation on the quote
183183
*
184184
* @var \Magento\Quote\Model\QuoteValidator
185185
*/
@@ -213,7 +213,7 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C
213213
protected $_customerFactory;
214214

215215
/**
216-
* Group repository
216+
* Repository for group to perform CRUD operations
217217
*
218218
* @var \Magento\Customer\Api\GroupRepositoryInterface
219219
*/
@@ -260,21 +260,21 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C
260260
protected $_objectCopyService;
261261

262262
/**
263-
* Address repository
263+
* Repository for customer address to perform crud operations
264264
*
265265
* @var \Magento\Customer\Api\AddressRepositoryInterface
266266
*/
267267
protected $addressRepository;
268268

269269
/**
270-
* Search criteria builder
270+
* It is used for building search criteria
271271
*
272272
* @var \Magento\Framework\Api\SearchCriteriaBuilder
273273
*/
274274
protected $searchCriteriaBuilder;
275275

276276
/**
277-
* Filter builder
277+
* This is used for holding builder object for filter service
278278
*
279279
* @var \Magento\Framework\Api\FilterBuilder
280280
*/
@@ -1356,7 +1356,7 @@ public function setBillingAddress(\Magento\Quote\Api\Data\AddressInterface $addr
13561356
{
13571357
$old = $this->getAddressesCollection()->getItemById($address->getId())
13581358
?? $this->getBillingAddress();
1359-
if (!empty($old)) {
1359+
if ($old !== null) {
13601360
$old->addData($address->getData());
13611361
} else {
13621362
$this->addAddress($address->setAddressType(Address::TYPE_BILLING));
@@ -1378,7 +1378,7 @@ public function setShippingAddress(\Magento\Quote\Api\Data\AddressInterface $add
13781378
} else {
13791379
$old = $this->getAddressesCollection()->getItemById($address->getId())
13801380
?? $this->getShippingAddress();
1381-
if (!empty($old)) {
1381+
if ($old !== null) {
13821382
$old->addData($address->getData());
13831383
} else {
13841384
$this->addAddress($address->setAddressType(Address::TYPE_SHIPPING));
@@ -1557,10 +1557,6 @@ public function removeItem($itemId)
15571557

15581558
if ($item) {
15591559
$item->setQuote($this);
1560-
/**
1561-
* If we remove item from quote - we can't use multishipping mode
1562-
*/
1563-
$this->setIsMultiShipping(false);
15641560
$item->isDeleted(true);
15651561
if ($item->getHasChildren()) {
15661562
foreach ($item->getChildren() as $child) {

dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Quote\Model;
99

1010
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Checkout\Model\Session as CheckoutSession;
1112
use Magento\Customer\Api\CustomerRepositoryInterface;
1213
use Magento\Customer\Api\Data\CustomerInterface;
1314
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
@@ -761,4 +762,51 @@ public function testValidateMinimumAmountWithPriceInclTaxAndDiscount()
761762
$this->assertEquals(5, $quote->getShippingAddress()->getBaseGrandTotal());
762763
$this->assertTrue($quote->validateMinimumAmount());
763764
}
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(
801+
1,
802+
$quote->getIsMultiShipping(),
803+
"Multi-shipping mode is disabled after quote item removal"
804+
);
805+
} else {
806+
$this->assertTrue(
807+
!is_null($idToDelete),
808+
"No Simple Product item with qty 1 to delete exists"
809+
);
810+
}
811+
}
764812
}

0 commit comments

Comments
 (0)