Skip to content

Commit 651bf2c

Browse files
committed
MAGETWO-39862: Can't disable Multishipping module
1 parent fefe1d6 commit 651bf2c

File tree

3 files changed

+59
-29
lines changed

3 files changed

+59
-29
lines changed

app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -289,35 +289,8 @@ public function getQuoteShippingAddressesItems()
289289
if ($this->_quoteShippingAddressesItems !== null) {
290290
return $this->_quoteShippingAddressesItems;
291291
}
292-
$items = [];
293-
$addresses = $this->getQuote()->getAllAddresses();
294-
foreach ($addresses as $address) {
295-
foreach ($address->getAllItems() as $item) {
296-
if ($item->getParentItemId()) {
297-
continue;
298-
}
299-
if ($item->getProduct()->getIsVirtual()) {
300-
$items[] = $item;
301-
continue;
302-
}
303-
if ($item->getQty() > 1) {
304-
for ($i = 0, $n = $item->getQty(); $i < $n; $i++) {
305-
if ($i == 0) {
306-
$addressItem = $item;
307-
} else {
308-
$addressItem = clone $item;
309-
}
310-
$addressItem->setQty(1)->setCustomerAddressId($address->getCustomerAddressId())->save();
311-
$items[] = $addressItem;
312-
}
313-
} else {
314-
$item->setCustomerAddressId($address->getCustomerAddressId());
315-
$items[] = $item;
316-
}
317-
}
318-
}
319-
$this->_quoteShippingAddressesItems = $items;
320-
return $items;
292+
$this->_quoteShippingAddressesItems = $this->getQuote()->getShippingAddressesItems();
293+
return $this->_quoteShippingAddressesItems;
321294
}
322295

323296
/**

app/code/Magento/Multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,12 @@ public function testSetQuoteCustomerBillingAddressForAddressLeak()
260260

261261
$this->assertEquals($this->model, $this->model->setQuoteCustomerBillingAddress($addressId));
262262
}
263+
264+
public function testGetQuoteShippingAddressesItems()
265+
{
266+
$quoteItem = $this->getMock('Magento\Quote\Model\Quote\Address\Item', [], [], '', false);
267+
$this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($this->quoteMock);
268+
$this->quoteMock->expects($this->once())->method('getShippingAddressesItems')->willReturn($quoteItem);
269+
$this->model->getQuoteShippingAddressesItems();
270+
}
263271
}

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C
344344
*/
345345
protected $shippingAssignmentFactory;
346346

347+
/**
348+
* Quote shipping addresses items cache
349+
*
350+
* @var array
351+
*/
352+
protected $shippingAddressesItems;
353+
347354
/**
348355
* @param \Magento\Framework\Model\Context $context
349356
* @param \Magento\Framework\Registry $registry
@@ -2413,6 +2420,48 @@ public function getCheckoutMethod($originalMethod = false)
24132420
return $this->_getData(self::KEY_CHECKOUT_METHOD);
24142421
}
24152422

2423+
/**
2424+
* Get quote items assigned to different quote addresses populated per item qty.
2425+
* Based on result array we can display each item separately
2426+
*
2427+
* @return array
2428+
*/
2429+
public function getShippingAddressesItems()
2430+
{
2431+
if ($this->shippingAddressesItems !== null) {
2432+
return $this->shippingAddressesItems;
2433+
}
2434+
$items = [];
2435+
$addresses = $this->getAllAddresses();
2436+
foreach ($addresses as $address) {
2437+
foreach ($address->getAllItems() as $item) {
2438+
if ($item->getParentItemId()) {
2439+
continue;
2440+
}
2441+
if ($item->getProduct()->getIsVirtual()) {
2442+
$items[] = $item;
2443+
continue;
2444+
}
2445+
if ($item->getQty() > 1) {
2446+
for ($itemIndex = 0, $itemQty = $item->getQty(); $itemIndex < $itemQty; $itemIndex++) {
2447+
if ($itemIndex == 0) {
2448+
$addressItem = $item;
2449+
} else {
2450+
$addressItem = clone $item;
2451+
}
2452+
$addressItem->setQty(1)->setCustomerAddressId($address->getCustomerAddressId())->save();
2453+
$items[] = $addressItem;
2454+
}
2455+
} else {
2456+
$item->setCustomerAddressId($address->getCustomerAddressId());
2457+
$items[] = $item;
2458+
}
2459+
}
2460+
}
2461+
$this->shippingAddressesItems = $items;
2462+
return $items;
2463+
}
2464+
24162465
/**
24172466
* Sets the payment method that is used to process the cart.
24182467
*

0 commit comments

Comments
 (0)