Skip to content

Commit 9d9b89a

Browse files
author
Igor Melnikov
committed
Merge remote-tracking branch 'upstream/develop' into create-default-hydrator
2 parents dc95d73 + 584af4d commit 9d9b89a

File tree

18 files changed

+243
-60
lines changed

18 files changed

+243
-60
lines changed

app/code/Magento/Checkout/Controller/Account/Create.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,38 @@ public function __construct(
5050
* @throws AlreadyExistsException
5151
* @throws NoSuchEntityException
5252
* @throws \Exception
53-
* @return void
53+
* @return \Magento\Framework\Controller\Result\Json
5454
*/
5555
public function execute()
5656
{
57+
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
58+
$resultJson = $this->_objectManager->get(\Magento\Framework\Controller\Result\JsonFactory::class)->create();
59+
5760
if ($this->customerSession->isLoggedIn()) {
58-
$this->messageManager->addError(__("Customer is already registered"));
59-
return;
61+
return $resultJson->setData(
62+
[
63+
'errors' => true,
64+
'message' => __('Customer is already registered')
65+
]
66+
);
6067
}
6168
$orderId = $this->checkoutSession->getLastOrderId();
6269
if (!$orderId) {
63-
$this->messageManager->addError(__("Your session has expired"));
64-
return;
70+
return $resultJson->setData(
71+
[
72+
'errors' => true,
73+
'message' => __('Your session has expired')
74+
]
75+
);
6576
}
6677
try {
6778
$this->orderCustomerService->create($orderId);
79+
return $resultJson->setData(
80+
[
81+
'errors' => false,
82+
'message' => __('A letter with further instructions will be sent to your email.')
83+
]
84+
);
6885
} catch (\Exception $e) {
6986
$this->messageManager->addException($e, $e->getMessage());
7087
throw $e;

app/code/Magento/Checkout/Test/Unit/Controller/Account/CreateTest.php

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class CreateTest extends \PHPUnit_Framework_TestCase
3535
*/
3636
protected $orderCustomerService;
3737

38+
/**
39+
* @var \PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
protected $objectManagerMock;
42+
3843
protected function setUp()
3944
{
4045
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -49,33 +54,77 @@ protected function setUp()
4954
);
5055
$this->messageManager = $this->getMock('\Magento\Framework\Message\ManagerInterface');
5156

57+
$this->objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class);
58+
$contextMock = $this->getMock(
59+
\Magento\Framework\App\Action\Context::class,
60+
['getObjectManager'],
61+
[],
62+
'',
63+
false
64+
);
65+
$contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock);
66+
5267
$this->action = $objectManagerHelper->getObject(
5368
'Magento\Checkout\Controller\Account\Create',
5469
[
5570
'checkoutSession' => $this->checkoutSession,
5671
'customerSession' => $this->customerSession,
5772
'orderCustomerService' => $this->orderCustomerService,
58-
'messageManager' => $this->messageManager
59-
73+
'messageManager' => $this->messageManager,
74+
'context' => $contextMock
6075
]
6176
);
6277
}
6378

6479
public function testExecuteAddsSessionMessageIfCustomerIsLoggedIn()
6580
{
81+
$jsonFactoryMock = $this->getMock(\Magento\Framework\Controller\Result\JsonFactory::class, [], [], '', false);
82+
$this->objectManagerMock->expects($this->once())
83+
->method('get')
84+
->with(\Magento\Framework\Controller\Result\JsonFactory::class)
85+
->willReturn($jsonFactoryMock);
86+
$jsonMock = $this->getMock(\Magento\Framework\Controller\Result\Json::class, [], [], '', false);
87+
$jsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock);
88+
6689
$this->customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
67-
$this->messageManager->expects($this->once())->method('addError')->with();
90+
91+
$jsonMock->expects($this->once())
92+
->method('setData')
93+
->with(
94+
[
95+
'errors' => true,
96+
'message' => __('Customer is already registered')
97+
]
98+
)->willReturnSelf();
6899
$this->action->execute();
69100
}
70101

71102
public function testExecute()
72103
{
104+
$jsonFactoryMock = $this->getMock(\Magento\Framework\Controller\Result\JsonFactory::class, [], [], '', false);
105+
$this->objectManagerMock->expects($this->once())
106+
->method('get')
107+
->with(\Magento\Framework\Controller\Result\JsonFactory::class)
108+
->willReturn($jsonFactoryMock);
109+
$jsonMock = $this->getMock(\Magento\Framework\Controller\Result\Json::class, [], [], '', false);
110+
$jsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock);
111+
73112
$this->customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
74113
$this->checkoutSession->expects($this->once())->method('getLastOrderId')->will($this->returnValue(100));
75114
$customer = $this->getMock('\Magento\Customer\Api\Data\CustomerInterface');
76115
$this->orderCustomerService->expects($this->once())->method('create')->with(100)->will(
77116
$this->returnValue($customer)
78117
);
118+
119+
$jsonMock->expects($this->once())
120+
->method('setData')
121+
->with(
122+
[
123+
'errors' => false,
124+
'message' => __('A letter with further instructions will be sent to your email.')
125+
]
126+
)->willReturnSelf();
127+
79128
$this->action->execute();
80129
}
81130
}

app/code/Magento/Checkout/view/frontend/templates/registration.phtml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
"config": {
2020
"registrationUrl": "<?php /* @escapeNotVerified */ echo $block->getCreateAccountUrl(); ?>",
2121
"email": "<?php /* @escapeNotVerified */ echo $block->getEmailAddress(); ?>"
22+
},
23+
"children": {
24+
"errors": {
25+
"component": "Magento_Ui/js/view/messages",
26+
"sortOrder": 0,
27+
"displayArea": "messages",
28+
"config": {
29+
"autoHideTimeOut": -1
30+
}
31+
}
2232
}
2333
}
2434
}

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ define(
135135
*/
136136
postcodeValidation: function () {
137137
var countryId = $('select[name="country_id"]').val(),
138-
validationResult = postcodeValidator.validate(postcodeElement.value(), countryId),
138+
validationResult,
139139
warnMessage;
140140

141141
if (postcodeElement == null || postcodeElement.value() == null) {
142142
return true;
143143
}
144144

145145
postcodeElement.warn(null);
146+
validationResult = postcodeValidator.validate(postcodeElement.value(), countryId);
146147

147148
if (!validationResult) {
148149
warnMessage = $t('Provided Zip/Postal Code seems to be invalid.');

app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-estimation.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* Copyright © 2016 Magento. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5-
/*jshint browser:true jquery:true*/
6-
/*global alert*/
75
define(
86
[
97
'jquery',
@@ -18,7 +16,7 @@ define(
1816
'Magento_Checkout/js/model/checkout-data-resolver',
1917
'mage/validation'
2018
],
21-
function(
19+
function (
2220
$,
2321
Component,
2422
selectShippingAddress,
@@ -31,6 +29,7 @@ define(
3129
checkoutDataResolver
3230
) {
3331
'use strict';
32+
3433
return Component.extend({
3534
defaults: {
3635
template: 'Magento_Checkout/cart/shipping-estimation'
@@ -43,18 +42,23 @@ define(
4342
initialize: function () {
4443
this._super();
4544
registry.async('checkoutProvider')(function (checkoutProvider) {
45+
var address, estimatedAddress;
46+
4647
checkoutDataResolver.resolveEstimationAddress();
47-
var address = quote.isVirtual() ? quote.billingAddress() : quote.shippingAddress(),
48-
estimatedAddress;
48+
address = quote.isVirtual() ? quote.billingAddress() : quote.shippingAddress();
49+
4950
if (address) {
50-
estimatedAddress = address.isEditable()
51-
? addressConverter.quoteAddressToFormAddressData(address)
52-
: addressConverter.quoteAddressToFormAddressData(addressConverter.addressToEstimationAddress(address));
51+
estimatedAddress = address.isEditable() ?
52+
addressConverter.quoteAddressToFormAddressData(address) :
53+
addressConverter.quoteAddressToFormAddressData(
54+
addressConverter.addressToEstimationAddress(address)
55+
);
5356
checkoutProvider.set(
5457
'shippingAddress',
5558
$.extend({}, checkoutProvider.get('shippingAddress'), estimatedAddress)
5659
);
5760
}
61+
5862
if (!quote.isVirtual()) {
5963
checkoutProvider.on('shippingAddress', function (shippingAddressData) {
6064
checkoutData.setShippingAddressFromData(shippingAddressData);
@@ -65,16 +69,24 @@ define(
6569
});
6670
}
6771
});
68-
},
6972

73+
return this;
74+
},
7075

7176
/**
7277
* @override
7378
*/
74-
initElement: function(element) {
79+
initElement: function (element) {
80+
this._super();
81+
7582
if (element.index === 'address-fieldsets') {
7683
shippingRatesValidator.bindChangeHandlers(element.elems(), true, 500);
84+
element.elems.subscribe(function (elems) {
85+
shippingRatesValidator.doElementBinding(elems[elems.length - 1], true, 500);
86+
});
7787
}
88+
89+
return this;
7890
},
7991

8092
/**
@@ -83,6 +95,7 @@ define(
8395
*/
8496
getEstimationInfo: function () {
8597
var addressData = null;
98+
8699
this.source.set('params.invalid', false);
87100
this.source.trigger('shippingAddress.data.validate');
88101

app/code/Magento/Checkout/view/frontend/web/js/view/cart/shipping-rates.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ define(
2424
checkoutData
2525
) {
2626
'use strict';
27+
2728
return Component.extend({
2829
defaults: {
2930
template: 'Magento_Checkout/cart/shipping-rates'
@@ -86,6 +87,7 @@ define(
8687
selectShippingMethod: function (methodData) {
8788
selectShippingMethodAction(methodData);
8889
checkoutData.setSelectedShippingRate(methodData['carrier_code'] + '_' + methodData['method_code']);
90+
8991
return true;
9092
}
9193
});

app/code/Magento/Checkout/view/frontend/web/js/view/registration.js

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,63 @@
55
/*jshint browser:true jquery:true*/
66
/*global alert*/
77
define(
8-
['jquery', 'uiComponent'],
9-
function ($, Component) {
8+
[
9+
'jquery',
10+
'uiComponent',
11+
'Magento_Ui/js/model/messageList'
12+
],
13+
function ($, Component, messageList) {
1014
'use strict';
15+
1116
return Component.extend({
1217
defaults: {
1318
template: 'Magento_Checkout/registration',
1419
accountCreated: false,
15-
creationStarted: false
20+
creationStarted: false,
21+
isFormVisible: true
1622
},
17-
/** Initialize observable properties */
23+
24+
/**
25+
* Initialize observable properties
26+
*/
1827
initObservable: function () {
1928
this._super()
2029
.observe('accountCreated')
30+
.observe('isFormVisible')
2131
.observe('creationStarted');
32+
2233
return this;
2334
},
24-
getEmailAddress: function() {
35+
36+
/**
37+
* @return {*}
38+
*/
39+
getEmailAddress: function () {
2540
return this.email;
2641
},
27-
createAccount: function() {
42+
43+
/**
44+
* Create new user account
45+
*/
46+
createAccount: function () {
2847
this.creationStarted(true);
29-
$.post(this.registrationUrl).done(
30-
function() {
31-
this.accountCreated(true)
48+
$.post(
49+
this.registrationUrl
50+
).done(
51+
function (response) {
52+
53+
if (response.errors == false) {
54+
this.accountCreated(true)
55+
} else {
56+
messageList.addErrorMessage(response);
57+
}
58+
this.isFormVisible(false);
59+
}.bind(this)
60+
).fail(
61+
function (response) {
62+
this.accountCreated(false)
63+
this.isFormVisible(false);
64+
messageList.addErrorMessage(response);
3265
}.bind(this)
3366
);
3467
}

app/code/Magento/Checkout/view/frontend/web/template/cart/shipping-rates.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030
"/>
3131
<label class="label" data-bind="attr: {for: 's_method_' + method_code}">
32-
<!-- ko text: method_title --><!-- /ko -->
32+
<!-- ko text: $data.method_title --><!-- /ko -->
3333
<!-- ko text: $parents[1].getFormattedPrice(amount) --><!-- /ko -->
3434
</label>
3535
<!-- /ko -->

app/code/Magento/Checkout/view/frontend/web/template/registration.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7+
<!-- ko foreach: getRegion('messages') -->
8+
<!-- ko template: getTemplate() --><!-- /ko -->
9+
<!--/ko-->
710
<div>
8-
<!-- ko ifnot: accountCreated -->
11+
<!-- ko if: isFormVisible -->
912
<p data-bind="i18n: 'You can track your order status by creating an account.'"></p>
1013
<p><span data-bind="i18n: 'Email Address'"></span>: <span data-bind="text: getEmailAddress()"></span></p>
1114
<form method="post" data-bind="submit: createAccount">

app/code/Magento/CheckoutAgreements/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
<type name="Magento\Checkout\Api\PaymentInformationManagementInterface">
1919
<plugin name="validate-agreements" type="Magento\CheckoutAgreements\Model\Checkout\Plugin\Validation"/>
2020
</type>
21+
<preference for="Magento\Checkout\Api\AgreementsValidatorInterface" type="Magento\CheckoutAgreements\Model\AgreementsValidator" />
2122
</config>

0 commit comments

Comments
 (0)