Skip to content

Commit 07120b1

Browse files
committed
MAGETWO-53177: Shopping Cart estimator displays zero totals when returning from Multishipping
1 parent 2f0225c commit 07120b1

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

app/code/Magento/Multishipping/Model/Cart/Controller/CartPlugin.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ class CartPlugin
1717
*/
1818
private $checkoutSession;
1919

20-
/**
21-
* @var \Magento\Multishipping\Model\Checkout\Type\Multishipping
22-
*/
23-
private $typeMultishipping;
24-
2520
/**
2621
* @var \Magento\Customer\Api\AddressRepositoryInterface
2722
*/
@@ -30,18 +25,15 @@ class CartPlugin
3025
/**
3126
* @param \Magento\Quote\Api\CartRepositoryInterface $cartRepository
3227
* @param \Magento\Checkout\Model\Session $checkoutSession
33-
* @param \Magento\Multishipping\Model\Checkout\Type\Multishipping $typeMultishipping
3428
* @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
3529
*/
3630
public function __construct(
3731
\Magento\Quote\Api\CartRepositoryInterface $cartRepository,
3832
\Magento\Checkout\Model\Session $checkoutSession,
39-
\Magento\Multishipping\Model\Checkout\Type\Multishipping $typeMultishipping,
4033
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
4134
) {
4235
$this->cartRepository = $cartRepository;
4336
$this->checkoutSession = $checkoutSession;
44-
$this->typeMultishipping = $typeMultishipping;
4537
$this->addressRepository = $addressRepository;
4638
}
4739

@@ -65,10 +57,13 @@ public function beforeDispatch(
6557
}
6658

6759
$shippingAddress = $quote->getShippingAddress();
68-
$defaultCustomerAddress = $this->addressRepository->getById(
69-
$this->typeMultishipping->getCustomerDefaultShippingAddress()
70-
);
71-
$shippingAddress->importCustomerAddressData($defaultCustomerAddress);
60+
$defaultShipping = $quote->getCustomer()->getDefaultShipping();
61+
if ($defaultShipping) {
62+
$defaultCustomerAddress = $this->addressRepository->getById(
63+
$defaultShipping
64+
);
65+
$shippingAddress->importCustomerAddressData($defaultCustomerAddress);
66+
}
7267
$this->cartRepository->save($quote);
7368
}
7469
}

app/code/Magento/Multishipping/Test/Unit/Model/Cart/Controller/CartPluginTest.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ class CartPluginTest extends \PHPUnit_Framework_TestCase
2222
*/
2323
private $checkoutSessionMock;
2424

25-
/**
26-
* @var \PHPUnit_Framework_MockObject_MockObject
27-
*/
28-
private $typeMultishippingMock;
29-
3025
/**
3126
* @var \PHPUnit_Framework_MockObject_MockObject
3227
*/
@@ -36,18 +31,10 @@ protected function setUp()
3631
{
3732
$this->cartRepositoryMock = $this->getMock(\Magento\Quote\Api\CartRepositoryInterface::class);
3833
$this->checkoutSessionMock = $this->getMock(\Magento\Checkout\Model\Session::class, [], [], '', false);
39-
$this->typeMultishippingMock = $this->getMock(
40-
\Magento\Multishipping\Model\Checkout\Type\Multishipping::class,
41-
[],
42-
[],
43-
'',
44-
false
45-
);
4634
$this->addressRepositoryMock = $this->getMock(\Magento\Customer\Api\AddressRepositoryInterface::class);
4735
$this->model = new \Magento\Multishipping\Model\Cart\Controller\CartPlugin(
4836
$this->cartRepositoryMock,
4937
$this->checkoutSessionMock,
50-
$this->typeMultishippingMock,
5138
$this->addressRepositoryMock
5239
);
5340
}
@@ -63,8 +50,7 @@ public function testBeforeDispatch()
6350
'getAllShippingAddresses',
6451
'removeAddress',
6552
'getShippingAddress',
66-
'setIsMultiShipping',
67-
'collectTotals'
53+
'getCustomer'
6854
],
6955
[],
7056
'',
@@ -81,10 +67,9 @@ public function testBeforeDispatch()
8167

8268
$shippingAddressMock = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false);
8369
$quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($shippingAddressMock);
84-
85-
$this->typeMultishippingMock->expects($this->once())
86-
->method('getCustomerDefaultShippingAddress')
87-
->willReturn($customerAddressId);
70+
$customerMock = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class);
71+
$quoteMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
72+
$customerMock->expects($this->once())->method('getDefaultShipping')->willReturn($customerAddressId);
8873

8974
$customerAddressMock = $this->getMock(\Magento\Customer\Api\Data\AddressInterface::class);
9075
$this->addressRepositoryMock->expects($this->once())

0 commit comments

Comments
 (0)