Skip to content

Commit 9890a61

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-99624' into 2.3-develop-pr22
2 parents 0731944 + cbe8e7d commit 9890a61

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

app/code/Magento/Checkout/Model/PaymentInformationManagement.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ public function savePaymentInformation(
112112
$quoteRepository = $this->getCartRepository();
113113
/** @var \Magento\Quote\Model\Quote $quote */
114114
$quote = $quoteRepository->getActive($cartId);
115+
$customerId = $quote->getBillingAddress()
116+
->getCustomerId();
117+
if (!$billingAddress->getCustomerId() && $customerId) {
118+
//It's necessary to verify the price rules with the customer data
119+
$billingAddress->setCustomerId($customerId);
120+
}
115121
$quote->removeAddress($quote->getBillingAddress()->getId());
116122
$quote->setBillingAddress($billingAddress);
117123
$quote->setDataChanges(true);

app/code/Magento/Checkout/Test/Unit/Model/PaymentInformationManagementTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,31 @@ public function testSavePaymentInformationAndPlaceOrderWithLocolizedException()
163163
$this->model->savePaymentInformationAndPlaceOrder($cartId, $paymentMock, $billingAddressMock);
164164
}
165165

166+
/**
167+
* Test for save payment and place order with new billing address
168+
*
169+
* @return void
170+
*/
171+
public function testSavePaymentInformationAndPlaceOrderWithNewBillingAddress(): void
172+
{
173+
$cartId = 100;
174+
$quoteBillingAddressId = 1;
175+
$customerId = 1;
176+
$quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
177+
$quoteBillingAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
178+
$billingAddressMock = $this->createMock(\Magento\Quote\Api\Data\AddressInterface::class);
179+
$paymentMock = $this->createMock(\Magento\Quote\Api\Data\PaymentInterface::class);
180+
181+
$quoteBillingAddress->method('getCustomerId')->willReturn($customerId);
182+
$quoteMock->method('getBillingAddress')->willReturn($quoteBillingAddress);
183+
$quoteBillingAddress->method('getId')->willReturn($quoteBillingAddressId);
184+
$this->cartRepositoryMock->method('getActive')->with($cartId)->willReturn($quoteMock);
185+
186+
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
187+
$billingAddressMock->expects($this->once())->method('setCustomerId')->with($customerId);
188+
$this->assertTrue($this->model->savePaymentInformation($cartId, $paymentMock, $billingAddressMock));
189+
}
190+
166191
/**
167192
* @param int $cartId
168193
* @param \PHPUnit_Framework_MockObject_MockObject $billingAddressMock
@@ -179,9 +204,10 @@ private function getMockForAssignBillingAddress($cartId, $billingAddressMock)
179204
['setLimitCarrier', 'getShippingMethod', 'getShippingRateByCode']
180205
);
181206
$this->cartRepositoryMock->expects($this->any())->method('getActive')->with($cartId)->willReturn($quoteMock);
182-
$quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($quoteBillingAddress);
207+
$quoteMock->method('getBillingAddress')->willReturn($quoteBillingAddress);
183208
$quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($quoteShippingAddress);
184209
$quoteBillingAddress->expects($this->once())->method('getId')->willReturn($billingAddressId);
210+
$quoteBillingAddress->expects($this->once())->method('getId')->willReturn($billingAddressId);
185211
$quoteMock->expects($this->once())->method('removeAddress')->with($billingAddressId);
186212
$quoteMock->expects($this->once())->method('setBillingAddress')->with($billingAddressMock);
187213
$quoteMock->expects($this->once())->method('setDataChanges')->willReturnSelf();

0 commit comments

Comments
 (0)