Skip to content

Commit 5a298ad

Browse files
authored
Merge pull request #3512 from magento-mpi/port-94437
[MPI]-port-94437
2 parents 6a8a6a0 + 3285f28 commit 5a298ad

File tree

14 files changed

+242
-123
lines changed

14 files changed

+242
-123
lines changed

app/code/Magento/Sales/Test/Mftf/Section/AdminOrderFormPaymentSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="AdminOrderFormPaymentSection">
12-
<element name="header" type="text" selector="#order-methods span.title"/>
12+
<element name="header" type="text" selector="#shipping-methods span.title"/>
1313
<element name="getShippingMethods" type="text" selector="#order-shipping_method a.action-default" timeout="30"/>
1414
<element name="flatRateOption" type="radio" selector="#s_method_flatrate_flatrate" timeout="30"/>
1515
<element name="shippingError" type="text" selector="#order[has_shipping]-error"/>

app/code/Magento/Sales/view/adminhtml/templates/order/create/data.phtml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,15 @@
4747
</div>
4848
</section>
4949

50-
<section id="order-methods" class="admin__page-section order-methods">
51-
<div class="admin__page-section-title">
52-
<span class="title"><?= /* @escapeNotVerified */ __('Payment &amp; Shipping Information') ?></span>
50+
<section id="shipping-methods" class="admin__page-section order-methods">
51+
<div id="order-shipping_method" class="admin__page-section-item order-shipping-method">
52+
<?= $block->getChildHtml('shipping_method') ?>
5353
</div>
54-
<div class="admin__page-section-content">
55-
<div id="order-billing_method" class="admin__page-section-item order-billing-method">
56-
<?= $block->getChildHtml('billing_method') ?>
57-
</div>
58-
<div id="order-shipping_method" class="admin__page-section-item order-shipping-method">
59-
<?= $block->getChildHtml('shipping_method') ?>
60-
</div>
54+
</section>
55+
56+
<section id="payment-methods" class="admin__page-section payment-methods">
57+
<div id="order-billing_method" class="admin__page-section-item order-billing-method">
58+
<?= $block->getChildHtml('billing_method') ?>
6159
</div>
6260
</section>
6361

app/code/Magento/Sales/view/adminhtml/templates/order/create/shipping/method/form.phtml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,8 @@ require(['prototype'], function(){
100100
</div>
101101
<script>
102102
require(["Magento_Sales/order/create/form"], function(){
103-
104103
order.overlay('shipping-method-overlay', <?php if ($block->getQuote()->isVirtual()): ?>false<?php else: ?>true<?php endif; ?>);
105104
order.overlay('address-shipping-overlay', <?php if ($block->getQuote()->isVirtual()): ?>false<?php else: ?>true<?php endif; ?>);
106-
107-
<?php if ($block->getQuote()->isVirtual()): ?>
108-
order.isOnlyVirtualProduct = true;
109-
<?php endif; ?>
105+
order.isOnlyVirtualProduct = <?= /* @noEscape */ $block->getQuote()->isVirtual() ? 'true' : 'false'; ?>;
110106
});
111107
</script>

app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js

Lines changed: 162 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
*/
55

66
define([
7-
"jquery",
7+
'jquery',
88
'Magento_Ui/js/modal/confirm',
99
'Magento_Ui/js/modal/alert',
10-
"mage/translate",
11-
"prototype",
12-
"Magento_Catalog/catalog/product/composite/configure",
10+
'mage/template',
11+
'text!Magento_Sales/templates/order/create/shipping/reload.html',
12+
'text!Magento_Sales/templates/order/create/payment/reload.html',
13+
'mage/translate',
14+
'prototype',
15+
'Magento_Catalog/catalog/product/composite/configure',
1316
'Magento_Ui/js/lib/view/utils/async'
14-
], function(jQuery, confirm, alert){
17+
], function (jQuery, confirm, alert, template, shippingTemplate, paymentTemplate) {
1518

1619
window.AdminOrder = new Class.create();
1720

@@ -29,7 +32,7 @@ define([
2932
this.gridProducts = $H({});
3033
this.gridProductsGift = $H({});
3134
this.billingAddressContainer = '';
32-
this.shippingAddressContainer= '';
35+
this.shippingAddressContainer = '';
3336
this.isShippingMethodReseted = data.shipping_method_reseted ? data.shipping_method_reseted : false;
3437
this.overlayData = $H({});
3538
this.giftMessageDataChanged = false;
@@ -39,7 +42,19 @@ define([
3942
this.isOnlyVirtualProduct = false;
4043
this.excludedPaymentMethods = [];
4144
this.summarizePrice = true;
42-
this.timerId = null;
45+
this.shippingTemplate = template(shippingTemplate, {
46+
data: {
47+
title: jQuery.mage.__('Shipping Method'),
48+
linkText: jQuery.mage.__('Get shipping methods and rates')
49+
}
50+
});
51+
this.paymentTemplate = template(paymentTemplate, {
52+
data: {
53+
title: jQuery.mage.__('Payment Method'),
54+
linkText: jQuery.mage.__('Get available payment methods')
55+
}
56+
});
57+
4358
jQuery.async('#order-items', (function(){
4459
this.dataArea = new OrderFormArea('data', $(this.getAreaId('data')), this);
4560
this.itemsArea = Object.extend(new OrderFormArea('items', $(this.getAreaId('items')), this), {
@@ -168,43 +183,51 @@ define([
168183

169184
var data = this.serializeData(container);
170185
data[el.name] = id;
171-
if(this.isShippingField(container) && !this.isShippingMethodReseted){
186+
187+
this.resetPaymentMethod();
188+
if (this.isShippingField(container) && !this.isShippingMethodReseted) {
172189
this.resetShippingMethod(data);
173-
}
174-
else{
190+
} else{
175191
this.saveData(data);
176192
}
177193
},
178194

179-
isShippingField : function(fieldId){
180-
if(this.shippingAsBilling){
195+
/**
196+
* Checks if the field belongs to the shipping address.
197+
*
198+
* @param {String} fieldId
199+
* @return {Boolean}
200+
*/
201+
isShippingField: function (fieldId) {
202+
if (this.shippingAsBilling) {
181203
return fieldId.include('billing');
182204
}
205+
183206
return fieldId.include('shipping');
184207
},
185208

186-
isBillingField : function(fieldId){
209+
/**
210+
* Checks if the field belongs to the billing address.
211+
*
212+
* @param {String} fieldId
213+
* @return {Boolean}
214+
*/
215+
isBillingField: function (fieldId) {
187216
return fieldId.include('billing');
188217
},
189218

190-
bindAddressFields : function(container) {
191-
var fields = $(container).select('input', 'select', 'textarea');
192-
for(var i=0;i<fields.length;i++){
193-
Event.observe(fields[i], 'change', this.triggerChangeEvent.bind(this));
194-
}
195-
},
196-
197219
/**
198-
* Calls changing address field handler after timeout to prevent multiple simultaneous calls.
220+
* Binds events on container form fields.
199221
*
200-
* @param {Event} event
222+
* @param {String} container
201223
*/
202-
triggerChangeEvent: function (event) {
203-
if (this.timerId) {
204-
window.clearTimeout(this.timerId);
205-
}
224+
bindAddressFields: function (container) {
225+
var fields = $(container).select('input', 'select', 'textarea'),
226+
i;
206227

207-
this.timerId = window.setTimeout(this.changeAddressField.bind(this), 500, event);
228+
for (i = 0; i < fields.length; i++) {
229+
jQuery(fields[i]).change(this.changeAddressField.bind(this));
230+
}
208231
},
209232

210233
/**
@@ -218,7 +241,8 @@ define([
218241
matchRes = field.name.match(re),
219242
type,
220243
name,
221-
data;
244+
data,
245+
resetShipping = false;
222246

223247
if (!matchRes) {
224248
return;
@@ -234,20 +258,31 @@ define([
234258
}
235259
data = data.toObject();
236260

237-
if (type === 'billing' && this.shippingAsBilling || type === 'shipping' && !this.shippingAsBilling) {
261+
if (type === 'billing' && this.shippingAsBilling) {
262+
this.syncAddressField(this.shippingAddressContainer, field.name, field.value);
263+
resetShipping = true;
264+
}
265+
266+
if (type === 'shipping' && !this.shippingAsBilling) {
267+
resetShipping = true;
268+
}
269+
270+
if (resetShipping) {
238271
data['reset_shipping'] = true;
239272
}
240273

241274
data['order[' + type + '_address][customer_address_id]'] = null;
242-
data['shipping_as_billing'] = jQuery('[name="shipping_same_as_billing"]').is(':checked') ? 1 : 0;
275+
data['shipping_as_billing'] = +this.shippingAsBilling;
243276

244277
if (name === 'customer_address_id') {
245278
data['order[' + type + '_address][customer_address_id]'] =
246279
$('order-' + type + '_address_customer_address_id').value;
247280
}
248281

282+
this.resetPaymentMethod();
283+
249284
if (data['reset_shipping']) {
250-
this.resetShippingMethod(data);
285+
this.resetShippingMethod();
251286
} else {
252287
this.saveData(data);
253288

@@ -257,7 +292,28 @@ define([
257292
}
258293
},
259294

260-
fillAddressFields : function(container, data){
295+
/**
296+
* Set address container form field value.
297+
*
298+
* @param {String} container - container ID
299+
* @param {String} fieldName - form field name
300+
* @param {*} fieldValue - form field value
301+
*/
302+
syncAddressField: function (container, fieldName, fieldValue) {
303+
var syncName;
304+
305+
if (this.isBillingField(fieldName)) {
306+
syncName = fieldName.replace('billing', 'shipping');
307+
}
308+
309+
$(container).select('[name="' + syncName + '"]').each(function (element) {
310+
if (~['input', 'textarea', 'select'].indexOf(element.tagName.toLowerCase())) {
311+
element.value = fieldValue;
312+
}
313+
});
314+
},
315+
316+
fillAddressFields: function(container, data){
261317
var regionIdElem = false;
262318
var regionIdElemValue = false;
263319

@@ -298,10 +354,15 @@ define([
298354
fields[i].setValue(data[name] ? data[name] : '');
299355
}
300356

301-
if (fields[i].changeUpdater) fields[i].changeUpdater();
357+
if (fields[i].changeUpdater) {
358+
fields[i].changeUpdater();
359+
}
360+
302361
if (name == 'region' && data['region_id'] && !data['region']){
303362
fields[i].value = data['region_id'];
304363
}
364+
365+
jQuery(fields[i]).trigger('change');
305366
}
306367
},
307368

@@ -332,46 +393,83 @@ define([
332393
}
333394
},
334395

335-
setShippingAsBilling : function(flag){
336-
var data;
337-
var areasToLoad = ['billing_method', 'shipping_address', 'totals', 'giftmessage'];
396+
/**
397+
* Equals shipping and billing addresses.
398+
*
399+
* @param {Boolean} flag
400+
*/
401+
setShippingAsBilling: function (flag) {
402+
var data,
403+
areasToLoad = ['billing_method', 'shipping_address', 'shipping_method', 'totals', 'giftmessage'];
404+
338405
this.disableShippingAddress(flag);
339-
if(flag){
340-
data = this.serializeData(this.billingAddressContainer);
341-
} else {
342-
data = this.serializeData(this.shippingAddressContainer);
343-
}
344-
areasToLoad.push('shipping_method');
406+
data = this.serializeData(flag ? this.billingAddressContainer : this.shippingAddressContainer);
345407
data = data.toObject();
346408
data['shipping_as_billing'] = flag ? 1 : 0;
347409
data['reset_shipping'] = 1;
348410
this.loadArea(areasToLoad, true, data);
349411
},
350412

351-
resetShippingMethod : function(data){
352-
var areasToLoad = ['billing_method', 'shipping_address', 'totals', 'giftmessage', 'items'];
353-
if(!this.isOnlyVirtualProduct) {
354-
areasToLoad.push('shipping_method');
355-
areasToLoad.push('shipping_address');
413+
/**
414+
* Replace shipping method area.
415+
*/
416+
resetShippingMethod: function () {
417+
if (!this.isOnlyVirtualProduct) {
418+
$(this.getAreaId('shipping_method')).update(this.shippingTemplate);
356419
}
420+
},
357421

358-
data['reset_shipping'] = 1;
359-
this.isShippingMethodReseted = true;
360-
this.loadArea(areasToLoad, true, data);
422+
/**
423+
* Replace payment method area.
424+
*/
425+
resetPaymentMethod: function () {
426+
$(this.getAreaId('billing_method')).update(this.paymentTemplate);
361427
},
362428

363-
loadShippingRates : function(){
429+
/**
430+
* Loads shipping options according to address data.
431+
*
432+
* @return {Boolean}
433+
*/
434+
loadShippingRates: function () {
435+
var addressContainer = this.shippingAsBilling ?
436+
'billingAddressContainer' :
437+
'shippingAddressContainer',
438+
data = this.serializeData(this[addressContainer]).toObject();
439+
440+
data['collect_shipping_rates'] = 1;
364441
this.isShippingMethodReseted = false;
365-
this.loadArea(['shipping_method', 'totals'], true, {collect_shipping_rates: 1});
442+
this.loadArea(['shipping_method', 'totals'], true, data);
443+
444+
return false;
366445
},
367446

368-
setShippingMethod : function(method){
447+
setShippingMethod: function(method) {
369448
var data = {};
449+
370450
data['order[shipping_method]'] = method;
371-
this.loadArea(['shipping_method', 'totals', 'billing_method'], true, data);
451+
this.loadArea([
452+
'shipping_method',
453+
'totals',
454+
'billing_method'
455+
], true, data);
372456
},
373457

374-
switchPaymentMethod : function(method){
458+
/**
459+
* Updates available payment
460+
* methods list according to order data.
461+
*
462+
* @return boolean
463+
*/
464+
loadPaymentMethods: function() {
465+
var data = this.serializeData(this.billingAddressContainer).toObject();
466+
467+
this.loadArea(['billing_method','totals'], true, data);
468+
469+
return false;
470+
},
471+
472+
switchPaymentMethod: function(method){
375473
jQuery('#edit_form')
376474
.off('submitOrder')
377475
.on('submitOrder', function(){
@@ -1149,9 +1247,15 @@ define([
11491247
|| this.excludedPaymentMethods.indexOf(this.paymentMethod) == -1);
11501248
},
11511249

1152-
serializeData : function(container){
1153-
var fields = $(container).select('input', 'select', 'textarea');
1154-
var data = Form.serializeElements(fields, true);
1250+
/**
1251+
* Serializes container form elements data.
1252+
*
1253+
* @param {String} container
1254+
* @return {Object}
1255+
*/
1256+
serializeData: function (container) {
1257+
var fields = $(container).select('input', 'select', 'textarea'),
1258+
data = Form.serializeElements(fields, true);
11551259

11561260
return $H(data);
11571261
},
@@ -1442,6 +1546,4 @@ define([
14421546
return this._label;
14431547
}
14441548
};
1445-
14461549
});
1447-

0 commit comments

Comments
 (0)