Skip to content

Commit d3338f6

Browse files
author
Igor Melnikov
committed
Merge remote-tracking branch 'upstream/develop' into MAGETWO-60420-remove-unserialize-from-menu
2 parents 3b7c728 + dd124b7 commit d3338f6

File tree

12 files changed

+178
-53
lines changed

12 files changed

+178
-53
lines changed

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor
1414
{
1515
/**
1616
* @var \Magento\Quote\Api\BillingAddressManagementInterface
17+
* @deprecated This call was substituted to eliminate extra quote::save call
1718
*/
1819
protected $billingAddressManagement;
1920

@@ -42,6 +43,11 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor
4243
*/
4344
private $logger;
4445

46+
/**
47+
* @var \Magento\Quote\Api\CartRepositoryInterface
48+
*/
49+
private $cartRepository;
50+
4551
/**
4652
* @param \Magento\Quote\Api\BillingAddressManagementInterface $billingAddressManagement
4753
* @param \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement
@@ -99,7 +105,19 @@ public function savePaymentInformation(
99105
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
100106
) {
101107
if ($billingAddress) {
102-
$this->billingAddressManagement->assign($cartId, $billingAddress);
108+
/** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
109+
$quoteRepository = $this->getCartRepository();
110+
/** @var \Magento\Quote\Model\Quote $quote */
111+
$quote = $quoteRepository->getActive($cartId);
112+
$quote->removeAddress($quote->getBillingAddress()->getId());
113+
$quote->setBillingAddress($billingAddress);
114+
$quote->setDataChanges(true);
115+
$shippingAddress = $quote->getShippingAddress();
116+
if ($shippingAddress && $shippingAddress->getShippingMethod()) {
117+
$shippingDataArray = explode('_', $shippingAddress->getShippingMethod());
118+
$shippingCarrier = array_shift($shippingDataArray);
119+
$shippingAddress->setLimitCarrier($shippingCarrier);
120+
}
103121
}
104122
$this->paymentMethodManagement->set($cartId, $paymentMethod);
105123
return true;
@@ -130,4 +148,19 @@ private function getLogger()
130148
}
131149
return $this->logger;
132150
}
151+
152+
/**
153+
* Get Cart repository
154+
*
155+
* @return \Magento\Quote\Api\CartRepositoryInterface
156+
* @deprecated
157+
*/
158+
private function getCartRepository()
159+
{
160+
if (!$this->cartRepository) {
161+
$this->cartRepository = \Magento\Framework\App\ObjectManager::getInstance()
162+
->get(\Magento\Quote\Api\CartRepositoryInterface::class);
163+
}
164+
return $this->cartRepository;
165+
}
133166
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public function saveAddressInformation(
144144

145145
/** @var \Magento\Quote\Model\Quote $quote */
146146
$quote = $this->quoteRepository->getActive($cartId);
147+
$address->setLimitCarrier($carrierCode);
147148
$quote = $this->prepareShippingAssignment($quote, $address, $carrierCode . '_' . $methodCode);
148149
$this->validateQuote($quote);
149150
$quote->setIsMultiShipping(false);

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

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66
namespace Magento\Checkout\Test\Unit\Model;
77

8-
use Magento\Framework\Exception\CouldNotSaveException;
9-
8+
/**
9+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
10+
*/
1011
class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
1112
{
1213
/**
@@ -34,6 +35,11 @@ class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase
3435
*/
3536
private $loggerMock;
3637

38+
/**
39+
* @var \PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
private $cartRepositoryMock;
42+
3743
protected function setUp()
3844
{
3945
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -46,7 +52,7 @@ protected function setUp()
4652
$this->cartManagementMock = $this->getMock(\Magento\Quote\Api\CartManagementInterface::class);
4753

4854
$this->loggerMock = $this->getMock(\Psr\Log\LoggerInterface::class);
49-
55+
$this->cartRepositoryMock = $this->getMockBuilder(\Magento\Quote\Api\CartRepositoryInterface::class)->getMock();
5056
$this->model = $objectManager->getObject(
5157
\Magento\Checkout\Model\PaymentInformationManagement::class,
5258
[
@@ -56,6 +62,7 @@ protected function setUp()
5662
]
5763
);
5864
$objectManager->setBackwardCompatibleProperty($this->model, 'logger', $this->loggerMock);
65+
$objectManager->setBackwardCompatibleProperty($this->model, 'cartRepository', $this->cartRepositoryMock);
5966
}
6067

6168
public function testSavePaymentInformationAndPlaceOrder()
@@ -65,9 +72,7 @@ public function testSavePaymentInformationAndPlaceOrder()
6572
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class);
6673
$billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class);
6774

68-
$this->billingAddressManagementMock->expects($this->once())
69-
->method('assign')
70-
->with($cartId, $billingAddressMock);
75+
$this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
7176
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
7277
$this->cartManagementMock->expects($this->once())->method('placeOrder')->with($cartId)->willReturn($orderId);
7378

@@ -87,9 +92,7 @@ public function testSavePaymentInformationAndPlaceOrderException()
8792
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class);
8893
$billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class);
8994

90-
$this->billingAddressManagementMock->expects($this->once())
91-
->method('assign')
92-
->with($cartId, $billingAddressMock);
95+
$this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
9396
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
9497
$exception = new \Exception(__('DB exception'));
9598
$this->loggerMock->expects($this->once())->method('critical');
@@ -104,7 +107,6 @@ public function testSavePaymentInformationAndPlaceOrderIfBillingAddressNotExist(
104107
$orderId = 200;
105108
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class);
106109

107-
$this->billingAddressManagementMock->expects($this->never())->method('assign');
108110
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
109111
$this->cartManagementMock->expects($this->once())->method('placeOrder')->with($cartId)->willReturn($orderId);
110112

@@ -120,9 +122,7 @@ public function testSavePaymentInformation()
120122
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class);
121123
$billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class);
122124

123-
$this->billingAddressManagementMock->expects($this->once())
124-
->method('assign')
125-
->with($cartId, $billingAddressMock);
125+
$this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
126126
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
127127

128128
$this->assertTrue($this->model->savePaymentInformation($cartId, $paymentMock, $billingAddressMock));
@@ -133,7 +133,6 @@ public function testSavePaymentInformationWithoutBillingAddress()
133133
$cartId = 100;
134134
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class);
135135

136-
$this->billingAddressManagementMock->expects($this->never())->method('assign');
137136
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
138137

139138
$this->assertTrue($this->model->savePaymentInformation($cartId, $paymentMock));
@@ -149,9 +148,8 @@ public function testSavePaymentInformationAndPlaceOrderWithLocolizedException()
149148
$paymentMock = $this->getMock(\Magento\Quote\Api\Data\PaymentInterface::class);
150149
$billingAddressMock = $this->getMock(\Magento\Quote\Api\Data\AddressInterface::class);
151150

152-
$this->billingAddressManagementMock->expects($this->once())
153-
->method('assign')
154-
->with($cartId, $billingAddressMock);
151+
$this->getMockForAssignBillingAddress($cartId, $billingAddressMock);
152+
155153
$this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock);
156154
$phrase = new \Magento\Framework\Phrase(__('DB exception'));
157155
$exception = new \Magento\Framework\Exception\LocalizedException($phrase);
@@ -160,4 +158,31 @@ public function testSavePaymentInformationAndPlaceOrderWithLocolizedException()
160158

161159
$this->model->savePaymentInformationAndPlaceOrder($cartId, $paymentMock, $billingAddressMock);
162160
}
161+
162+
/**
163+
* @param int $cartId
164+
* @param \PHPUnit_Framework_MockObject_MockObject $billingAddressMock
165+
*/
166+
private function getMockForAssignBillingAddress($cartId, $billingAddressMock)
167+
{
168+
$billingAddressId = 1;
169+
$quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false);
170+
$quoteBillingAddress = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false);
171+
$quoteShippingAddress = $this->getMock(
172+
\Magento\Quote\Model\Quote\Address::class,
173+
['setLimitCarrier', 'getShippingMethod'],
174+
[],
175+
'',
176+
false
177+
);
178+
$this->cartRepositoryMock->expects($this->any())->method('getActive')->with($cartId)->willReturn($quoteMock);
179+
$quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($quoteBillingAddress);
180+
$quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($quoteShippingAddress);
181+
$quoteBillingAddress->expects($this->once())->method('getId')->willReturn($billingAddressId);
182+
$quoteMock->expects($this->once())->method('removeAddress')->with($billingAddressId);
183+
$quoteMock->expects($this->once())->method('setBillingAddress')->with($billingAddressMock);
184+
$quoteMock->expects($this->once())->method('setDataChanges')->willReturnSelf();
185+
$quoteShippingAddress->expects($this->any())->method('getShippingMethod')->willReturn('flatrate_flatrate');
186+
$quoteShippingAddress->expects($this->once())->method('setLimitCarrier')->with('flatrate')->willReturnSelf();
187+
}
163188
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ protected function setUp()
109109
'importCustomerAddressData',
110110
'save',
111111
'getShippingRateByCode',
112-
'getShippingMethod'
112+
'getShippingMethod',
113+
'setLimitCarrier'
113114
],
114115
[],
115116
'',
@@ -208,7 +209,7 @@ public function testSaveAddressInformationIfCartIsEmpty()
208209
private function setShippingAssignmentsMocks($shippingMethod)
209210
{
210211
$this->quoteMock->expects($this->once())->method('getExtensionAttributes')->willReturn(null);
211-
212+
$this->shippingAddressMock->expects($this->once())->method('setLimitCarrier');
212213
$this->cartExtensionMock = $this->getMock(
213214
\Magento\Quote\Api\Data\CartExtension::class,
214215
['getShippingAssignments', 'setShippingAssignments'],

app/code/Magento/Quote/Model/CustomerManagement.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public function populateCustomerInfo(QuoteEntity $quote)
6262
$quote->getPasswordHash()
6363
);
6464
$quote->setCustomer($customer);
65-
} else {
66-
$this->customerRepository->save($customer);
6765
}
6866
if (!$quote->getBillingAddress()->getId() && $customer->getDefaultBilling()) {
6967
$quote->getBillingAddress()->importCustomerAddressData(

app/code/Magento/Quote/Test/Unit/Model/CustomerManagementTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,34 @@ public function testPopulateCustomerInfo()
158158
->willReturn($this->customerMock);
159159
$this->customerManagement->populateCustomerInfo($this->quoteMock);
160160
}
161+
162+
public function testPopulateCustomerInfoForExistingCustomer()
163+
{
164+
$this->quoteMock->expects($this->once())
165+
->method('getCustomer')
166+
->willReturn($this->customerMock);
167+
$this->customerMock->expects($this->atLeastOnce())
168+
->method('getId')
169+
->willReturn(1);
170+
$this->customerMock->expects($this->atLeastOnce())
171+
->method('getDefaultBilling')
172+
->willReturn(100500);
173+
$this->quoteMock->expects($this->atLeastOnce())
174+
->method('getBillingAddress')
175+
->willReturn($this->quoteAddressMock);
176+
$this->quoteMock->expects($this->atLeastOnce())
177+
->method('getShippingAddress')
178+
->willReturn($this->quoteAddressMock);
179+
$this->quoteAddressMock->expects($this->atLeastOnce())
180+
->method('getId')
181+
->willReturn(null);
182+
$this->customerAddressRepositoryMock->expects($this->atLeastOnce())
183+
->method('getById')
184+
->with(100500)
185+
->willReturn($this->customerAddressMock);
186+
$this->quoteAddressMock->expects($this->atLeastOnce())
187+
->method('importCustomerAddressData')
188+
->willReturnSelf();
189+
$this->customerManagement->populateCustomerInfo($this->quoteMock);
190+
}
161191
}

app/code/Magento/Ui/view/base/web/js/form/element/date.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ define([
5353
pickerDefaultDateFormat: 'MM/dd/y', // ICU Date Format
5454
pickerDefaultTimeFormat: 'h:mm a', // ICU Time Format
5555

56+
elementTmpl: 'ui/form/element/date',
57+
5658
/**
57-
* Moment compatible format used for moment conversion
58-
* of date from datePicker
59+
* Format needed by moment timezone for conversion
5960
*/
60-
momentFormat: 'MM/DD/YYYY',
61-
62-
elementTmpl: 'ui/form/element/date',
61+
timezoneFormat: 'YYYY-MM-DD HH:mm',
6362

6463
listens: {
6564
'value': 'onValueChange',
@@ -141,15 +140,17 @@ define([
141140
*/
142141
onShiftedValueChange: function (shiftedValue) {
143142
var value,
144-
formattedValue;
143+
formattedValue,
144+
momentValue;
145145

146146
if (shiftedValue) {
147+
momentValue = moment(shiftedValue, this.pickerDateTimeFormat);
148+
147149
if (this.options.showsTime) {
148-
formattedValue = moment(shiftedValue).format('YYYY-MM-DD HH:mm');
150+
formattedValue = moment(momentValue).format(this.timezoneFormat);
149151
value = moment.tz(formattedValue, this.storeTimeZone).tz('UTC').toISOString();
150152
} else {
151-
value = moment(shiftedValue, this.momentFormat);
152-
value = value.format(this.outputDateFormat);
153+
value = momentValue.format(this.outputDateFormat);
153154
}
154155
} else {
155156
value = '';
@@ -166,8 +167,6 @@ define([
166167
*/
167168
prepareDateTimeFormats: function () {
168169
this.pickerDateTimeFormat = this.options.dateFormat;
169-
this.momentFormat = this.options.dateFormat ?
170-
utils.convertToMomentFormat(this.options.dateFormat) : this.momentFormat;
171170

172171
if (this.options.showsTime) {
173172
this.pickerDateTimeFormat += ' ' + this.options.timeFormat;

dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/RegisterCustomerFrontendEntityTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<constraint name="Magento\Newsletter\Test\Constraint\AssertCustomerIsSubscribedToNewsletter" />
3333
</variation>
3434
<variation name="RegisterCustomerFrontendEntityTestVariation3" summary="Register Customer" ticketId="MAGETWO-12394">
35-
<data name="tag" xsi:type="string">test_type:acceptance_test, test_type:extended_acceptance_test</data>
35+
<data name="tag" xsi:type="string">test_type:acceptance_test, test_type:extended_acceptance_test, stable:no</data>
3636
<data name="customer/data/firstname" xsi:type="string">john</data>
3737
<data name="customer/data/lastname" xsi:type="string">doe</data>
3838
<data name="customer/data/email" xsi:type="string">johndoe%isolation%@example.com</data>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/*eslint max-nested-callbacks: 0*/
7+
8+
define([
9+
'Magento_Ui/js/form/element/date',
10+
'mageUtils',
11+
'moment'
12+
], function (DateElement, utils, moment) {
13+
'use strict';
14+
15+
describe('Magento_Ui/js/form/element/date', function () {
16+
var params, model;
17+
18+
beforeEach(function () {
19+
params = {
20+
dataScope: 'abstract',
21+
options: {
22+
showsTime: true
23+
}
24+
};
25+
model = new DateElement(params);
26+
});
27+
28+
it('Check prepareDateTimeFormats function', function () {
29+
spyOn(utils, 'convertToMomentFormat').and.callThrough();
30+
model.prepareDateTimeFormats();
31+
expect(utils.convertToMomentFormat).toHaveBeenCalled();
32+
});
33+
34+
it('Check onShiftedValueChange function', function () {
35+
spyOn(moment, 'tz').and.callThrough();
36+
model.onShiftedValueChange('2016-12-23 9:11 PM');
37+
expect(moment.tz).toHaveBeenCalled();
38+
});
39+
40+
});
41+
});

0 commit comments

Comments
 (0)