-
- = $block->getChildHtml('billing_method') ?>
-
-
- = $block->getChildHtml('shipping_method') ?>
-
+
+
+
+
+ = $block->getChildHtml('billing_method') ?>
diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/create/shipping/method/form.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/create/shipping/method/form.phtml
index 9e0394f6430bd..65d3a612e5133 100644
--- a/app/code/Magento/Sales/view/adminhtml/templates/order/create/shipping/method/form.phtml
+++ b/app/code/Magento/Sales/view/adminhtml/templates/order/create/shipping/method/form.phtml
@@ -100,12 +100,8 @@ require(['prototype'], function(){
diff --git a/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js b/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js
index 259ca2165e647..05449c478152f 100644
--- a/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js
+++ b/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js
@@ -4,14 +4,17 @@
*/
define([
- "jquery",
+ 'jquery',
'Magento_Ui/js/modal/confirm',
'Magento_Ui/js/modal/alert',
- "mage/translate",
- "prototype",
- "Magento_Catalog/catalog/product/composite/configure",
+ 'mage/template',
+ 'text!Magento_Sales/templates/order/create/shipping/reload.html',
+ 'text!Magento_Sales/templates/order/create/payment/reload.html',
+ 'mage/translate',
+ 'prototype',
+ 'Magento_Catalog/catalog/product/composite/configure',
'Magento_Ui/js/lib/view/utils/async'
-], function(jQuery, confirm, alert){
+], function(jQuery, confirm, alert, template, shippingTemplate, paymentTemplate){
window.AdminOrder = new Class.create();
@@ -29,7 +32,7 @@ define([
this.gridProducts = $H({});
this.gridProductsGift = $H({});
this.billingAddressContainer = '';
- this.shippingAddressContainer= '';
+ this.shippingAddressContainer = '';
this.isShippingMethodReseted = data.shipping_method_reseted ? data.shipping_method_reseted : false;
this.overlayData = $H({});
this.giftMessageDataChanged = false;
@@ -40,6 +43,19 @@ define([
this.excludedPaymentMethods = [];
this.summarizePrice = true;
this.timerId = null;
+ this.shippingTemplate = template(shippingTemplate, {
+ data: {
+ title: jQuery.mage.__('Shipping Method'),
+ linkText: jQuery.mage.__('Get shipping methods and rates')
+ }
+ });
+ this.paymentTemplate = template(paymentTemplate, {
+ data: {
+ title: jQuery.mage.__('Payment Method'),
+ linkText: jQuery.mage.__('Get available payment methods')
+ }
+ });
+
jQuery.async('#order-items', (function(){
this.dataArea = new OrderFormArea('data', $(this.getAreaId('data')), this);
this.itemsArea = Object.extend(new OrderFormArea('items', $(this.getAreaId('items')), this), {
@@ -168,10 +184,11 @@ define([
var data = this.serializeData(container);
data[el.name] = id;
- if(this.isShippingField(container) && !this.isShippingMethodReseted){
+
+ this.resetPaymentMethod();
+ if (this.isShippingField(container) && !this.isShippingMethodReseted) {
this.resetShippingMethod(data);
- }
- else{
+ } else{
this.saveData(data);
}
},
@@ -239,13 +256,14 @@ define([
}
data['order[' + type + '_address][customer_address_id]'] = null;
- data['shipping_as_billing'] = jQuery('[name="shipping_same_as_billing"]').is(':checked') ? 1 : 0;
+ data['shipping_as_billing'] = +this.isShippingAsBilling();
if (name === 'customer_address_id') {
data['order[' + type + '_address][customer_address_id]'] =
$('order-' + type + '_address_customer_address_id').value;
}
+ this.resetPaymentMethod();
if (data['reset_shipping']) {
this.resetShippingMethod(data);
} else {
@@ -348,30 +366,69 @@ define([
this.loadArea(areasToLoad, true, data);
},
- resetShippingMethod : function(data){
- var areasToLoad = ['billing_method', 'shipping_address', 'totals', 'giftmessage', 'items'];
- if(!this.isOnlyVirtualProduct) {
- areasToLoad.push('shipping_method');
- areasToLoad.push('shipping_address');
+ /**
+ * Checks if shipping address is corresponds to billing address.
+ *
+ * @return {Boolean}
+ */
+ isShippingAsBilling: function () {
+ return jQuery('[name="shipping_same_as_billing"]').is(':checked');
+ },
+
+ resetShippingMethod: function() {
+ if (!this.isOnlyVirtualProduct) {
+ $(this.getAreaId('shipping_method')).update(this.shippingTemplate);
}
+ },
- data['reset_shipping'] = 1;
- this.isShippingMethodReseted = true;
- this.loadArea(areasToLoad, true, data);
+ resetPaymentMethod: function() {
+ $(this.getAreaId('billing_method')).update(this.paymentTemplate);
},
- loadShippingRates : function(){
+ /**
+ * Loads shipping options according to address data.
+ *
+ * @return {Boolean}
+ */
+ loadShippingRates: function () {
+ var addressContainer = this.isShippingAsBilling() ?
+ 'billingAddressContainer' :
+ 'shippingAddressContainer',
+ data = this.serializeData(this[addressContainer]).toObject();
+
+ data['collect_shipping_rates'] = 1;
this.isShippingMethodReseted = false;
- this.loadArea(['shipping_method', 'totals'], true, {collect_shipping_rates: 1});
+ this.loadArea(['shipping_method', 'totals'], true, data);
+
+ return false;
},
- setShippingMethod : function(method){
+ setShippingMethod: function(method) {
var data = {};
+
data['order[shipping_method]'] = method;
- this.loadArea(['shipping_method', 'totals', 'billing_method'], true, data);
+ this.loadArea([
+ 'shipping_method',
+ 'totals',
+ 'billing_method'
+ ], true, data);
},
- switchPaymentMethod : function(method){
+ /**
+ * Updates available payment
+ * methods list according to order data.
+ *
+ * @return boolean
+ */
+ loadPaymentMethods: function() {
+ var data = this.serializeData(this.billingAddressContainer).toObject();
+
+ this.loadArea(['billing_method','totals'], true, data);
+
+ return false;
+ },
+
+ switchPaymentMethod: function(method){
jQuery('#edit_form')
.off('submitOrder')
.on('submitOrder', function(){
@@ -1149,9 +1206,15 @@ define([
|| this.excludedPaymentMethods.indexOf(this.paymentMethod) == -1);
},
- serializeData : function(container){
- var fields = $(container).select('input', 'select', 'textarea');
- var data = Form.serializeElements(fields, true);
+ /**
+ * Serializes container form elements data.
+ *
+ * @param {String} container
+ * @return {Object}
+ */
+ serializeData: function (container) {
+ var fields = $(container).select('input', 'select', 'textarea'),
+ data = Form.serializeElements(fields, true);
return $H(data);
},
diff --git a/app/code/Magento/Sales/view/adminhtml/web/templates/order/create/payment/reload.html b/app/code/Magento/Sales/view/adminhtml/web/templates/order/create/payment/reload.html
new file mode 100644
index 0000000000000..c503f3c678ab6
--- /dev/null
+++ b/app/code/Magento/Sales/view/adminhtml/web/templates/order/create/payment/reload.html
@@ -0,0 +1,18 @@
+
+
+