Skip to content

Commit dcfb60b

Browse files
author
Sergey Shvets
committed
MAGETWO-60238: Address form is blank when editing multiple address order in checkout
1 parent 383d18a commit dcfb60b

File tree

2 files changed

+77
-51
lines changed

2 files changed

+77
-51
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ public function setShippingItemsInformation($info)
395395
}
396396
}
397397

398+
$this->prepareShippingAssignment($quote);
399+
398400
/**
399401
* Delete all not virtual quote items which are not added to shipping address
400402
* MultishippingQty should be defined for each quote item when it processed with _addShippingItem

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

Lines changed: 75 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Multishipping\Test\Unit\Model\Checkout\Type;
77

8+
use Magento\Quote\Model\ShippingAssignment;
9+
810
/**
911
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1012
*/
@@ -106,13 +108,10 @@ protected function setUp()
106108
'',
107109
false
108110
);
109-
$this->addressRepositoryMock = $this->getMock(
110-
\Magento\Customer\Api\AddressRepositoryInterface::class,
111-
[],
112-
[],
113-
'',
114-
false
115-
);
111+
$this->addressRepositoryMock = $this->getMockBuilder(\Magento\Customer\Api\AddressRepositoryInterface::class)
112+
->setMethods([])
113+
->disableOriginalConstructor()
114+
->getMock();
116115
/** This is used to get past _init() which is called in construct. */
117116
$data['checkout_session'] = $this->checkoutSessionMock;
118117
$this->quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false);
@@ -121,13 +120,10 @@ protected function setUp()
121120
$this->checkoutSessionMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($this->quoteMock);
122121
$this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomerDataObject')
123122
->willReturn($this->customerMock);
124-
$this->totalsCollectorMock = $this->getMock(
125-
\Magento\Quote\Model\Quote\TotalsCollector::class,
126-
[],
127-
[],
128-
'',
129-
false
130-
);
123+
$this->totalsCollectorMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\TotalsCollector::class)
124+
->setMethods([])
125+
->disableOriginalConstructor()
126+
->getMock();
131127
$this->model = new \Magento\Multishipping\Model\Checkout\Type\Multishipping(
132128
$this->checkoutSessionMock,
133129
$this->customerSessionMock,
@@ -221,6 +217,8 @@ public function testSetShippingItemsInformation()
221217
$resultMock->expects($this->atLeastOnce())->method('getItems')->willReturn([$addressItemMock]);
222218
$addressItemMock->expects($this->atLeastOnce())->method('getId')->willReturn(null);
223219

220+
$this->mockShippingAssignment();
221+
224222
$this->assertEquals($this->model, $this->model->setShippingItemsInformation($info));
225223
}
226224

@@ -330,54 +328,80 @@ public function testSetShippingMethods()
330328

331329
$methodsArray = [1 => 'flatrate_flatrate', 2 => 'tablerate_bestway'];
332330
$addressId = 1;
333-
$addressMock = $this->getMock(
334-
\Magento\Quote\Model\Quote\Address::class,
335-
['getId', 'setShippingMethod'],
336-
[],
337-
'',
338-
false
339-
);
340-
$extensionAttributesMock = $this->getMock(
341-
\Magento\Quote\Api\Data\CartExtension::class,
342-
['setShippingAssignments'],
343-
[],
344-
'',
345-
false
346-
);
347-
$shippingAssignmentMock = $this->getMock(
348-
\Magento\Quote\Model\ShippingAssignment::class,
349-
['getShipping', 'setShipping'],
350-
[],
351-
'',
352-
false
353-
);
354-
$shippingMock = $this->getMock(\Magento\Quote\Model\Shipping::class, ['setMethod'], [], '', false);
331+
$addressMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address::class)
332+
->setMethods(['getId', 'setShippingMethod'])
333+
->disableOriginalConstructor()
334+
->getMock();
355335

356336
$addressMock->expects($this->once())->method('getId')->willReturn($addressId);
357337
$this->quoteMock->expects($this->once())->method('getAllShippingAddresses')->willReturn([$addressMock]);
358338
$addressMock->expects($this->once())->method('setShippingMethod')->with($methodsArray[$addressId]);
359-
//mock for prepareShippingAssignment
360-
$this->quoteMock
339+
340+
$this->mockShippingAssignment();
341+
342+
//save mock
343+
$this->quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf();
344+
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
345+
$this->model->setShippingMethods($methodsArray);
346+
}
347+
348+
/**
349+
* @param ShippingAssignment $shippingAssignmentMock
350+
* @return \Magento\Quote\Api\Data\CartExtension|\PHPUnit_Framework_MockObject_MockObject
351+
*/
352+
private function getExtensionAttributesMock(ShippingAssignment $shippingAssignmentMock)
353+
{
354+
$extensionAttributesMock = $this->getMockBuilder(\Magento\Quote\Api\Data\CartExtension::class)
355+
->setMethods(['setShippingAssignments'])
356+
->getMock();
357+
358+
$extensionAttributesMock
361359
->expects($this->once())
362-
->method('getExtensionAttributes')
363-
->willReturn($extensionAttributesMock);
360+
->method('setShippingAssignments')
361+
->with([$shippingAssignmentMock])
362+
->willReturnSelf();
363+
364+
return $extensionAttributesMock;
365+
}
366+
367+
/**
368+
* @return ShippingAssignment | \PHPUnit_Framework_MockObject_MockObject
369+
*/
370+
private function getShippingAssignmentMock()
371+
{
372+
$shippingAssignmentMock = $this->getMockBuilder(ShippingAssignment::class)
373+
->disableOriginalConstructor()
374+
->setMethods(['getShipping', 'setShipping'])
375+
->getMock();
376+
$shippingMock = $this->getMockBuilder(\Magento\Quote\Model\Shipping::class)
377+
->disableOriginalConstructor()
378+
->setMethods(['setMethod'])
379+
->getMock();
380+
381+
$shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock);
382+
$shippingMock->expects($this->once())->method('setMethod')->with(null)->willReturnSelf();
383+
$shippingAssignmentMock->expects($this->once())->method('setShipping')->with($shippingMock);
384+
385+
return $shippingAssignmentMock;
386+
}
387+
388+
private function mockShippingAssignment()
389+
{
390+
$shippingAssignmentMock = $this->getShippingAssignmentMock();
391+
392+
$extensionAttributesMock = $this->getExtensionAttributesMock($shippingAssignmentMock);
393+
364394
$this->shippingAssignmentProcessorMock
365395
->expects($this->once())
366396
->method('create')
367397
->with($this->quoteMock)
368398
->willReturn($shippingAssignmentMock);
369-
$shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock);
370-
$shippingMock->expects($this->once())->method('setMethod')->with(null)->willReturnSelf();
371-
$shippingAssignmentMock->expects($this->once())->method('setShipping')->with($shippingMock);
372-
$extensionAttributesMock
399+
400+
$this->quoteMock
373401
->expects($this->once())
374-
->method('setShippingAssignments')
375-
->with([$shippingAssignmentMock])
376-
->willReturnSelf();
402+
->method('getExtensionAttributes')
403+
->willReturn($extensionAttributesMock);
404+
377405
$this->quoteMock->expects($this->once())->method('setExtensionAttributes')->with($extensionAttributesMock);
378-
//save mock
379-
$this->quoteMock->expects($this->once())->method('collectTotals')->willReturnSelf();
380-
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
381-
$this->model->setShippingMethods($methodsArray);
382406
}
383407
}

0 commit comments

Comments
 (0)