Skip to content

Commit 0ceb41d

Browse files
author
Ann Beeskau
committed
Merge branch 'mainline-develop' into CICD-1633
2 parents 4957bdc + 986ab1c commit 0ceb41d

File tree

14 files changed

+619
-147
lines changed

14 files changed

+619
-147
lines changed

app/code/Magento/Checkout/Block/Onepage.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,14 @@ public function getCheckoutConfig()
126126
{
127127
return $this->configProvider->getConfig();
128128
}
129+
130+
/**
131+
* Get base url for block.
132+
*
133+
* @return string
134+
*/
135+
public function getBaseUrl()
136+
{
137+
return $this->_storeManager->getStore()->getBaseUrl();
138+
}
129139
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Checkout\Test\Unit\Block;
7+
8+
class OnepageTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Checkout\Block\Onepage
12+
*/
13+
protected $model;
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $configProviderMock;
19+
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $storeManagerMock;
24+
25+
/**
26+
* @var \PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $formKeyMock;
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $layoutProcessorMock;
34+
35+
protected function setUp()
36+
{
37+
$contextMock = $this->getMock('\Magento\Framework\View\Element\Template\Context', [], [], '', false);
38+
$directoryHelperMock = $this->getMock('\Magento\Directory\Helper\Data', [], [], '', false);
39+
$configCacheTypeMock = $this->getMock('\Magento\Framework\App\Cache\Type\Config', [], [], '', false);
40+
$customerSessionMock = $this->getMock('\Magento\Customer\Model\Session', [], [], '', false);
41+
$resourceSessionMock = $this->getMock('\Magento\Checkout\Model\Session', [], [], '', false);
42+
$addressConfigMock = $this->getMock('\Magento\Customer\Model\Address\Config', [], [], '', false);
43+
$httpContextMock = $this->getMock('\Magento\Framework\App\Http\Context', [], [], '', false);
44+
$addressMapperMock = $this->getMock('\Magento\Customer\Model\Address\Mapper', [], [], '', false);
45+
$this->formKeyMock = $this->getMock('\Magento\Framework\Data\Form\FormKey', [], [], '', false);
46+
$this->configProviderMock = $this->getMock(
47+
'\Magento\Checkout\Model\CompositeConfigProvider',
48+
[],
49+
[],
50+
'',
51+
false
52+
);
53+
$countryCollectionFactoryMock = $this->getMock(
54+
'\Magento\Directory\Model\Resource\Country\CollectionFactory',
55+
[],
56+
[],
57+
'',
58+
false
59+
);
60+
$regionCollectionFactoryMock = $this->getMock(
61+
'\Magento\Directory\Model\Resource\Region\CollectionFactory',
62+
[],
63+
[],
64+
'',
65+
false
66+
);
67+
$customerRepositoryMock = $this->getMock(
68+
'\Magento\Customer\Api\CustomerRepositoryInterface',
69+
[],
70+
[],
71+
'',
72+
false
73+
);
74+
75+
$this->storeManagerMock = $this->getMock('\Magento\Store\Model\StoreManagerInterface', [], [], '', false);
76+
$contextMock->expects($this->once())->method('getStoreManager')->willReturn($this->storeManagerMock);
77+
$this->layoutProcessorMock = $this->getMock(
78+
'\Magento\Checkout\Block\Checkout\LayoutProcessorInterface',
79+
[],
80+
[],
81+
'',
82+
false
83+
);
84+
85+
$this->model = new \Magento\Checkout\Block\Onepage(
86+
$contextMock,
87+
$directoryHelperMock,
88+
$configCacheTypeMock,
89+
$customerSessionMock,
90+
$resourceSessionMock,
91+
$countryCollectionFactoryMock,
92+
$regionCollectionFactoryMock,
93+
$customerRepositoryMock,
94+
$addressConfigMock,
95+
$httpContextMock,
96+
$addressMapperMock,
97+
$this->formKeyMock,
98+
$this->configProviderMock,
99+
[$this->layoutProcessorMock]
100+
);
101+
}
102+
103+
public function testGetBaseUrl()
104+
{
105+
$baseUrl = 'http://magento.com';
106+
$storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
107+
108+
$storeMock->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
109+
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
110+
111+
$this->assertEquals($baseUrl, $this->model->getBaseUrl());
112+
}
113+
114+
public function testGetCheckoutConfig()
115+
{
116+
$checkoutConfig = ['checkout', 'config'];
117+
$this->configProviderMock->expects($this->once())->method('getConfig')->willReturn($checkoutConfig);
118+
119+
$this->assertEquals($checkoutConfig, $this->model->getCheckoutConfig());
120+
}
121+
122+
public function testGetFormKey()
123+
{
124+
$formKey = 'form_key';
125+
$this->formKeyMock->expects($this->once())->method('getFormKey')->willReturn($formKey);
126+
127+
$this->assertEquals($formKey, $this->model->getFormKey());
128+
}
129+
130+
public function testGetJsLayout()
131+
{
132+
$processedLayout = ['layout' => ['processed' => true]];
133+
$jsonLayout = '{"layout":{"processed":true}}';
134+
$this->layoutProcessorMock->expects($this->once())->method('process')->with([])->willReturn($processedLayout);
135+
136+
$this->assertEquals($jsonLayout, $this->model->getJsLayout());
137+
}
138+
}

app/code/Magento/Checkout/view/frontend/web/js/action/select-billing-address.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,31 @@ define(
1313
'uiRegistry',
1414
'../model/url-builder',
1515
'mage/storage',
16-
'../model/payment-service'
17-
16+
'../model/payment-service',
17+
'underscore'
1818
],
19-
function (quote, addressList, navigator, selectShippingAddress, registry, urlBuilder, storage, paymentService) {
19+
function (quote, addressList, navigator, selectShippingAddress, registry, urlBuilder, storage, paymentService, _) {
2020
"use strict";
2121
var actionCallback;
2222
var result = function (billingAddress, useForShipping, additionalData) {
23+
var copyBillingToShipping = function() {
24+
var shippingAddressSource = registry.get('checkoutProvider'),
25+
shippingAddress = shippingAddressSource.get('shippingAddress');
26+
for (var property in billingAddress) {
27+
if (billingAddress.hasOwnProperty(property) && shippingAddress.hasOwnProperty(property)) {
28+
if (typeof billingAddress[property] === 'string') {
29+
shippingAddressSource.set('shippingAddress.' + property, billingAddress[property]);
30+
} else {
31+
shippingAddressSource.set('shippingAddress.' + property, _.clone(billingAddress[property]));
32+
}
33+
}
34+
}
35+
};
2336
additionalData = additionalData || {};
2437
quote.setBillingAddress(billingAddress);
2538
if (useForShipping() === '1' && !quote.isVirtual()) {
2639
if (!billingAddress.customerAddressId) {
27-
// update shipping address data in corresponding provider
28-
var shippingAddressSource = registry.get('checkoutProvider');
29-
var shippingAddress = shippingAddressSource.get('shippingAddress');
30-
for (var property in billingAddress) {
31-
if (billingAddress.hasOwnProperty(property)
32-
&& shippingAddress.hasOwnProperty(property)
33-
) {
34-
shippingAddressSource.set('shippingAddress.' + property, billingAddress[property]);
35-
}
36-
}
40+
copyBillingToShipping();
3741
}
3842
selectShippingAddress(billingAddress, useForShipping, additionalData);
3943
} else if (quote.isVirtual()) {
@@ -72,6 +76,9 @@ define(
7276
);
7377
} else {
7478
navigator.setCurrent('billingAddress').goNext();
79+
if (addressList.isBillingSameAsShipping) {
80+
copyBillingToShipping();
81+
}
7582
}
7683
};
7784
result.setActionCallback = function (value) {

app/code/Magento/Checkout/view/frontend/web/js/model/addresslist.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,8 @@ define(['jquery'], function($) {
2222
return address;
2323
},
2424
getAddresses: function() {
25-
if (addresses.indexOf(this.newAddress) == -1) {
26-
this.add(this.newAddress);
27-
}
28-
return addresses;
25+
return addresses.slice(0);
2926
},
30-
newAddress: {
31-
getAddressInline: function() {
32-
return 'New Address';
33-
},
34-
customerAddressId: null
35-
}
27+
isBillingSameAsShipping: false
3628
};
3729
});

app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
* See COPYING.txt for license details.
44
*/
55
/*jshint browser:true*/
6-
/*global define,alert*/
6+
/*global define*/
77
define(
88
[
99
"jquery",
1010
'Magento_Ui/js/form/form',
1111
'ko',
1212
'Magento_Customer/js/model/customer',
1313
'../action/select-billing-address',
14-
'Magento_Checkout/js/model/step-navigator',
14+
'../model/step-navigator',
1515
'../model/quote',
16-
'../model/addresslist',
17-
'../action/check-email-availability',
18-
'mage/validation'
16+
'../model/addresslist'
1917
],
20-
function ($, Component, ko, customer, selectBillingAddress, navigator, quote, addressList, checkEmailAvailability) {
18+
function ($, Component, ko, customer, selectBillingAddress, navigator, quote, addressList) {
2119
"use strict";
2220
var stepName = 'billingAddress';
2321
var newAddressSelected = ko.observable(false);
@@ -35,12 +33,23 @@ define(
3533
return navigator.getStepClassAttributes(stepName);
3634
},
3735
stepNumber: navigator.getStepNumber(stepName),
38-
billingAddresses: customer.getBillingAddressList(),
39-
selectedBillingAddressId: addressList.getAddresses()[0].customerAddressId,
36+
billingAddresses: function() {
37+
var newAddress = {
38+
getAddressInline: function() {
39+
return $.mage.__('New address');
40+
},
41+
customerAddressId: null
42+
},
43+
addresses = addressList.getAddresses();
44+
addresses.push(newAddress);
45+
return addresses;
46+
},
47+
selectedBillingAddressId: ko.observable(
48+
addressList.getAddresses().length ? addressList.getAddresses()[0].customerAddressId : null
49+
),
4050
isVisible: navigator.isStepVisible(stepName),
4151
useForShipping: "1",
4252
quoteIsVirtual: quote.isVirtual(),
43-
isEmailCheckComplete: $.Deferred(),
4453
billingAddressesOptionsText: function(item) {
4554
return item.getAddressInline();
4655
},
@@ -53,42 +62,32 @@ define(
5362
return additionalData;
5463
},
5564
submitBillingAddress: function() {
56-
if (this.selectedBillingAddressId) {
57-
var additionalData = this.checkUseForShipping(this.useForShipping);
65+
var additionalData = this.checkUseForShipping(this.useForShipping);
66+
if (this.selectedBillingAddressId()) {
5867
selectBillingAddress(
59-
addressList.getAddressById(this.selectedBillingAddressId),
68+
addressList.getAddressById(this.selectedBillingAddressId()),
6069
this.useForShipping,
6170
additionalData
6271
);
6372
} else {
64-
var that = this;
6573
this.validate();
66-
$.when(this.isEmailCheckComplete).done( function() {
67-
if (!that.source.get('params.invalid')) {
68-
var addressData = that.source.get('billingAddress');
69-
var additionalData = that.checkUseForShipping(that.useForShipping);
70-
/**
71-
* All the the input fields that are not a part of the address but need to be submitted
72-
* in the same request must have data-scope attribute set
73-
*/
74-
var additionalFields = $('input[data-scope="additionalAddressData"]').serializeArray();
75-
additionalFields.forEach(function (field) {
76-
additionalData[field.name] = field.value;
77-
});
78-
if (quote.getCheckoutMethod()() && !customer.isLoggedIn()()) {
79-
addressData.email = that.source.get('customerDetails.email');
80-
}
81-
if($(billingFormSelector).validation() && $(billingFormSelector).validation('isValid')) {
82-
selectBillingAddress(addressData, that.useForShipping, additionalData);
83-
}
74+
if (!this.source.get('params.invalid')) {
75+
var addressData = this.source.get('billingAddress');
76+
/**
77+
* All the the input fields that are not a part of the address (e. g. CAPTCHA) but need to be
78+
* submitted in the same request must have data-scope attribute set
79+
*/
80+
var additionalFields = $('input[data-scope="additionalAddressData"]').serializeArray();
81+
additionalFields.forEach(function (field) {
82+
additionalData[field.name] = field.value;
83+
});
84+
if (quote.getCheckoutMethod()() && !customer.isLoggedIn()()) {
85+
addressData.email = this.source.get('customerDetails.email');
86+
}
87+
if($(billingFormSelector).validation() && $(billingFormSelector).validation('isValid')) {
88+
selectBillingAddress(addressData, this.useForShipping, additionalData);
8489
}
85-
}).fail( function() {
86-
alert(
87-
"There is already a registered customer using this email address. " +
88-
"Please log in using this email address or enter a different email address " +
89-
"to register your account."
90-
);
91-
});
90+
}
9291
}
9392
},
9493
navigateToCurrentStep: function() {
@@ -103,11 +102,7 @@ define(
103102
return newAddressSelected();
104103
},
105104
onAddressChange: function (value) {
106-
if (value === null) {
107-
newAddressSelected(true);
108-
} else {
109-
newAddressSelected(false);
110-
}
105+
value() === null ? newAddressSelected(true) : newAddressSelected(false);
111106
},
112107
validate: function() {
113108
var fields = $(billingFormSelector).find('input, select');
@@ -116,7 +111,6 @@ define(
116111
fields.trigger('change');
117112
this.source.trigger('billingAddress.data.validate');
118113
this.validateAdditionalAddressFields();
119-
this.isEmailCheckComplete.resolve();
120114
},
121115
validateAdditionalAddressFields: function() {
122116
$(billingFormSelector).validation();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ define(
8383
return info;
8484
},
8585
getPaymentMethodCallbacks: function() {
86-
var callbacks = [this.getActiveMethodView().afterSave];
86+
var callbacks = [this.getActiveMethodView().afterSave.bind(this.getActiveMethodView())];
8787

8888
_.each(this.getAdditionalMethods(), function(elem) {
8989
if (elem.isActive()) {
90-
callbacks = _.union(callbacks, [elem.afterSave]);
90+
callbacks = _.union(callbacks, [elem.afterSave.bind(elem)]);
9191
}
9292
});
9393

0 commit comments

Comments
 (0)