Skip to content

Commit 7deec55

Browse files
author
Stanislav Idolov
committed
Merge remote-tracking branch 'origin/bugfix' into jsonapi_compliant
2 parents 33feb5a + f7f995b commit 7deec55

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
@@ -2398,6 +2405,48 @@ public function getCheckoutMethod($originalMethod = false)
23982405
return $this->_getData(self::KEY_CHECKOUT_METHOD);
23992406
}
24002407

2408+
/**
2409+
* Get quote items assigned to different quote addresses populated per item qty.
2410+
* Based on result array we can display each item separately
2411+
*
2412+
* @return array
2413+
*/
2414+
public function getShippingAddressesItems()
2415+
{
2416+
if ($this->shippingAddressesItems !== null) {
2417+
return $this->shippingAddressesItems;
2418+
}
2419+
$items = [];
2420+
$addresses = $this->getAllAddresses();
2421+
foreach ($addresses as $address) {
2422+
foreach ($address->getAllItems() as $item) {
2423+
if ($item->getParentItemId()) {
2424+
continue;
2425+
}
2426+
if ($item->getProduct()->getIsVirtual()) {
2427+
$items[] = $item;
2428+
continue;
2429+
}
2430+
if ($item->getQty() > 1) {
2431+
for ($itemIndex = 0, $itemQty = $item->getQty(); $itemIndex < $itemQty; $itemIndex++) {
2432+
if ($itemIndex == 0) {
2433+
$addressItem = $item;
2434+
} else {
2435+
$addressItem = clone $item;
2436+
}
2437+
$addressItem->setQty(1)->setCustomerAddressId($address->getCustomerAddressId())->save();
2438+
$items[] = $addressItem;
2439+
}
2440+
} else {
2441+
$item->setCustomerAddressId($address->getCustomerAddressId());
2442+
$items[] = $item;
2443+
}
2444+
}
2445+
}
2446+
$this->shippingAddressesItems = $items;
2447+
return $items;
2448+
}
2449+
24012450
/**
24022451
* Sets the payment method that is used to process the cart.
24032452
*

0 commit comments

Comments
 (0)