Skip to content

Commit 00b6f61

Browse files
authored
Merge pull request #2448 from magento-mpi/MPI-BUGFIXES
[MPI] Bugfixes
2 parents a9a51f6 + c7e63be commit 00b6f61

File tree

19 files changed

+297
-187
lines changed

19 files changed

+297
-187
lines changed

app/code/Magento/Braintree/Model/AvsEmsCodeMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AvsEmsCodeMapper implements PaymentVerificationInterface
2424
*
2525
* @var string
2626
*/
27-
private static $unavailableCode = 'U';
27+
private static $unavailableCode = '';
2828

2929
/**
3030
* List of mapping AVS codes

app/code/Magento/Braintree/Test/Unit/Model/AvsEmsCodeMapperTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public function testGetCodeWithException()
8484
public function getCodeDataProvider()
8585
{
8686
return [
87-
['avsZip' => null, 'avsStreet' => null, 'expected' => 'U'],
88-
['avsZip' => null, 'avsStreet' => 'M', 'expected' => 'U'],
89-
['avsZip' => 'M', 'avsStreet' => null, 'expected' => 'U'],
90-
['avsZip' => 'M', 'avsStreet' => 'Unknown', 'expected' => 'U'],
91-
['avsZip' => 'I', 'avsStreet' => 'A', 'expected' => 'U'],
87+
['avsZip' => null, 'avsStreet' => null, 'expected' => ''],
88+
['avsZip' => null, 'avsStreet' => 'M', 'expected' => ''],
89+
['avsZip' => 'M', 'avsStreet' => null, 'expected' => ''],
90+
['avsZip' => 'M', 'avsStreet' => 'Unknown', 'expected' => ''],
91+
['avsZip' => 'I', 'avsStreet' => 'A', 'expected' => ''],
9292
['avsZip' => 'M', 'avsStreet' => 'M', 'expected' => 'Y'],
9393
['avsZip' => 'N', 'avsStreet' => 'M', 'expected' => 'A'],
9494
['avsZip' => 'M', 'avsStreet' => 'N', 'expected' => 'Z'],

app/code/Magento/Catalog/view/frontend/web/js/product/breadcrumbs.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ define([
1010
'use strict';
1111

1212
return function (widget) {
13+
1314
$.widget('mage.breadcrumbs', widget, {
1415
options: {
1516
categoryUrlSuffix: '',
@@ -26,9 +27,9 @@ define([
2627
menu = $(this.options.menuContainer).data('mageMenu');
2728

2829
if (typeof menu === 'undefined') {
29-
$(this.options.menuContainer).on('menucreate', function () {
30-
this._super();
31-
}.bind(this));
30+
this._on($(this.options.menuContainer), {
31+
'menucreate': this._super
32+
});
3233
} else {
3334
this._super();
3435
}

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Quote\Api\CartRepositoryInterface;
1212
use Magento\Framework\Exception\CouldNotSaveException;
13+
use Magento\Quote\Model\Quote;
1314

1415
/**
1516
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -135,13 +136,19 @@ public function savePaymentInformation(
135136
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
136137
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
137138
) {
139+
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
140+
/** @var Quote $quote */
141+
$quote = $this->cartRepository->getActive($quoteIdMask->getQuoteId());
142+
138143
if ($billingAddress) {
139144
$billingAddress->setEmail($email);
140-
$this->billingAddressManagement->assign($cartId, $billingAddress);
145+
$quote->removeAddress($quote->getBillingAddress()->getId());
146+
$quote->setBillingAddress($billingAddress);
147+
$quote->setDataChanges(true);
141148
} else {
142-
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
143-
$this->cartRepository->getActive($quoteIdMask->getQuoteId())->getBillingAddress()->setEmail($email);
149+
$quote->getBillingAddress()->setEmail($email);
144150
}
151+
$this->limitShippingCarrier($quote);
145152

146153
$this->paymentMethodManagement->set($cartId, $paymentMethod);
147154
return true;
@@ -169,4 +176,22 @@ private function getLogger()
169176
}
170177
return $this->logger;
171178
}
179+
180+
/**
181+
* Limits shipping rates request by carrier from shipping address.
182+
*
183+
* @param Quote $quote
184+
*
185+
* @return void
186+
* @see \Magento\Shipping\Model\Shipping::collectRates
187+
*/
188+
private function limitShippingCarrier(Quote $quote)
189+
{
190+
$shippingAddress = $quote->getShippingAddress();
191+
if ($shippingAddress && $shippingAddress->getShippingMethod()) {
192+
$shippingDataArray = explode('_', $shippingAddress->getShippingMethod());
193+
$shippingCarrier = array_shift($shippingDataArray);
194+
$shippingAddress->setLimitCarrier($shippingCarrier);
195+
}
196+
}
172197
}

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

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
use Magento\Framework\App\ResourceConnection;
99
use Magento\Framework\DB\Adapter\AdapterInterface;
10+
use Magento\Quote\Model\Quote;
11+
use Magento\Quote\Model\Quote\Address;
12+
use Magento\Quote\Model\QuoteIdMask;
1013

1114
/**
1215
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -95,6 +98,7 @@ public function testSavePaymentInformationAndPlaceOrder()
9598
$email = 'email@magento.com';
9699
$paymentMock = $this->createMock(\Magento\Quote\Api\Data\PaymentInterface::class);
97100
$billingAddressMock = $this->createMock(\Magento\Quote\Api\Data\AddressInterface::class);
101+
$this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
98102

99103
$billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf();
100104

@@ -118,10 +122,6 @@ public function testSavePaymentInformationAndPlaceOrder()
118122
->willReturn($adapterMockForCheckout);
119123
$adapterMockForCheckout->expects($this->once())->method('beginTransaction');
120124
$adapterMockForCheckout->expects($this->once())->method('commit');
121-
122-
$this->billingAddressManagementMock->expects($this->once())
123-
->method('assign')
124-
->with($cartId, $billingAddressMock);
125125
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
126126
$this->cartManagementMock->expects($this->once())->method('placeOrder')->with($cartId)->willReturn($orderId);
127127

@@ -142,6 +142,7 @@ public function testSavePaymentInformationAndPlaceOrderException()
142142
$paymentMock = $this->createMock(\Magento\Quote\Api\Data\PaymentInterface::class);
143143
$billingAddressMock = $this->createMock(\Magento\Quote\Api\Data\AddressInterface::class);
144144

145+
$this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
145146
$billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf();
146147

147148
$adapterMockForSales = $this->getMockBuilder(AdapterInterface::class)
@@ -164,10 +165,7 @@ public function testSavePaymentInformationAndPlaceOrderException()
164165
->willReturn($adapterMockForCheckout);
165166
$adapterMockForCheckout->expects($this->once())->method('beginTransaction');
166167
$adapterMockForCheckout->expects($this->once())->method('rollback');
167-
168-
$this->billingAddressManagementMock->expects($this->once())
169-
->method('assign')
170-
->with($cartId, $billingAddressMock);
168+
171169
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
172170
$exception = new \Exception(__('DB exception'));
173171
$this->cartManagementMock->expects($this->once())->method('placeOrder')->willThrowException($exception);
@@ -181,11 +179,9 @@ public function testSavePaymentInformation()
181179
$email = 'email@magento.com';
182180
$paymentMock = $this->createMock(\Magento\Quote\Api\Data\PaymentInterface::class);
183181
$billingAddressMock = $this->createMock(\Magento\Quote\Api\Data\AddressInterface::class);
182+
$this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
184183
$billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf();
185184

186-
$this->billingAddressManagementMock->expects($this->once())
187-
->method('assign')
188-
->with($cartId, $billingAddressMock);
189185
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
190186

191187
$this->assertTrue($this->model->savePaymentInformation($cartId, $email, $paymentMock, $billingAddressMock));
@@ -197,13 +193,13 @@ public function testSavePaymentInformationWithoutBillingAddress()
197193
$email = 'email@magento.com';
198194
$paymentMock = $this->createMock(\Magento\Quote\Api\Data\PaymentInterface::class);
199195
$billingAddressMock = $this->createMock(\Magento\Quote\Api\Data\AddressInterface::class);
200-
$quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
196+
$quoteMock = $this->createMock(Quote::class);
201197

202198
$billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf();
203199

204200
$this->billingAddressManagementMock->expects($this->never())->method('assign');
205201
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
206-
$quoteIdMaskMock = $this->createPartialMock(\Magento\Quote\Model\QuoteIdMask::class, ['getQuoteId', 'load']);
202+
$quoteIdMaskMock = $this->createPartialMock(QuoteIdMask::class, ['getQuoteId', 'load']);
207203
$this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($quoteIdMaskMock);
208204
$quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf();
209205
$quoteIdMaskMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
@@ -224,6 +220,15 @@ public function testSavePaymentInformationAndPlaceOrderWithLocolizedException()
224220
$paymentMock = $this->createMock(\Magento\Quote\Api\Data\PaymentInterface::class);
225221
$billingAddressMock = $this->createMock(\Magento\Quote\Api\Data\AddressInterface::class);
226222

223+
$quoteMock = $this->createMock(Quote::class);
224+
$quoteMock->method('getBillingAddress')->willReturn($billingAddressMock);
225+
$this->cartRepositoryMock->method('getActive')->with($cartId)->willReturn($quoteMock);
226+
227+
$quoteIdMask = $this->createPartialMock(QuoteIdMask::class, ['getQuoteId', 'load']);
228+
$this->quoteIdMaskFactoryMock->method('create')->willReturn($quoteIdMask);
229+
$quoteIdMask->method('load')->with($cartId, 'masked_id')->willReturnSelf();
230+
$quoteIdMask->method('getQuoteId')->willReturn($cartId);
231+
227232
$billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf();
228233

229234
$adapterMockForSales = $this->getMockBuilder(AdapterInterface::class)
@@ -246,10 +251,7 @@ public function testSavePaymentInformationAndPlaceOrderWithLocolizedException()
246251
->willReturn($adapterMockForCheckout);
247252
$adapterMockForCheckout->expects($this->once())->method('beginTransaction');
248253
$adapterMockForCheckout->expects($this->once())->method('rollback');
249-
250-
$this->billingAddressManagementMock->expects($this->once())
251-
->method('assign')
252-
->with($cartId, $billingAddressMock);
254+
253255
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
254256
$phrase = new \Magento\Framework\Phrase(__('DB exception'));
255257
$exception = new \Magento\Framework\Exception\LocalizedException($phrase);
@@ -258,4 +260,55 @@ public function testSavePaymentInformationAndPlaceOrderWithLocolizedException()
258260

259261
$this->model->savePaymentInformationAndPlaceOrder($cartId, $email, $paymentMock, $billingAddressMock);
260262
}
263+
264+
/**
265+
* @param int $cartId
266+
* @param \PHPUnit_Framework_MockObject_MockObject $billingAddressMock
267+
* @return void
268+
*/
269+
private function getMockForAssignBillingAddress($cartId, $billingAddressMock)
270+
{
271+
$quoteIdMask = $this->createPartialMock(QuoteIdMask::class, ['getQuoteId', 'load']);
272+
$this->quoteIdMaskFactoryMock->method('create')
273+
->willReturn($quoteIdMask);
274+
$quoteIdMask->method('load')
275+
->with($cartId, 'masked_id')
276+
->willReturnSelf();
277+
$quoteIdMask->method('getQuoteId')
278+
->willReturn($cartId);
279+
280+
$billingAddressId = 1;
281+
$quote = $this->createMock(Quote::class);
282+
$quoteBillingAddress = $this->createMock(Address::class);
283+
$quoteShippingAddress = $this->createPartialMock(
284+
Address::class,
285+
['setLimitCarrier', 'getShippingMethod']
286+
);
287+
$this->cartRepositoryMock->method('getActive')
288+
->with($cartId)
289+
->willReturn($quote);
290+
$quote->expects($this->once())
291+
->method('getBillingAddress')
292+
->willReturn($quoteBillingAddress);
293+
$quote->expects($this->once())
294+
->method('getShippingAddress')
295+
->willReturn($quoteShippingAddress);
296+
$quoteBillingAddress->expects($this->once())
297+
->method('getId')
298+
->willReturn($billingAddressId);
299+
$quote->expects($this->once())
300+
->method('removeAddress')
301+
->with($billingAddressId);
302+
$quote->expects($this->once())
303+
->method('setBillingAddress')
304+
->with($billingAddressMock);
305+
$quote->expects($this->once())
306+
->method('setDataChanges')
307+
->willReturnSelf();
308+
$quoteShippingAddress->method('getShippingMethod')
309+
->willReturn('flatrate_flatrate');
310+
$quoteShippingAddress->expects($this->once())
311+
->method('setLimitCarrier')
312+
->with('flatrate');
313+
}
261314
}

0 commit comments

Comments
 (0)