init
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'Magento_Checkout/js/model/address-converter'
|
||||
], function (addressConverter) {
|
||||
'use strict';
|
||||
|
||||
return function (addressData) {
|
||||
var address = addressConverter.formAddressDataToQuoteAddress(addressData);
|
||||
|
||||
/**
|
||||
* Returns new customer billing address type.
|
||||
*
|
||||
* @returns {String}
|
||||
*/
|
||||
address.getType = function () {
|
||||
return 'new-customer-billing-address';
|
||||
};
|
||||
|
||||
return address;
|
||||
};
|
||||
});
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'Magento_Customer/js/model/address-list',
|
||||
'Magento_Checkout/js/model/address-converter'
|
||||
], function (addressList, addressConverter) {
|
||||
'use strict';
|
||||
|
||||
return function (addressData) {
|
||||
var address = addressConverter.formAddressDataToQuoteAddress(addressData),
|
||||
isAddressUpdated = addressList().some(function (currentAddress, index, addresses) {
|
||||
if (currentAddress.getKey() == address.getKey()) { //eslint-disable-line eqeqeq
|
||||
addresses[index] = address;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (!isAddressUpdated) {
|
||||
addressList.push(address);
|
||||
} else {
|
||||
addressList.valueHasMutated();
|
||||
}
|
||||
|
||||
return address;
|
||||
};
|
||||
});
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/url-builder',
|
||||
'mage/storage',
|
||||
'Magento_Checkout/js/model/error-processor',
|
||||
'Magento_Customer/js/model/customer',
|
||||
'Magento_Checkout/js/model/payment/method-converter',
|
||||
'Magento_Checkout/js/model/payment-service'
|
||||
], function ($, quote, urlBuilder, storage, errorProcessor, customer, methodConverter, paymentService) {
|
||||
'use strict';
|
||||
|
||||
return function (deferred, messageContainer) {
|
||||
var serviceUrl;
|
||||
|
||||
deferred = deferred || $.Deferred();
|
||||
|
||||
/**
|
||||
* Checkout for guest and registered customer.
|
||||
*/
|
||||
if (!customer.isLoggedIn()) {
|
||||
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/payment-information', {
|
||||
cartId: quote.getQuoteId()
|
||||
});
|
||||
} else {
|
||||
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
|
||||
}
|
||||
|
||||
return storage.get(
|
||||
serviceUrl, false
|
||||
).done(function (response) {
|
||||
quote.setTotals(response.totals);
|
||||
paymentService.setPaymentMethods(methodConverter(response['payment_methods']));
|
||||
deferred.resolve();
|
||||
}).fail(function (response) {
|
||||
errorProcessor.process(response, messageContainer);
|
||||
deferred.reject();
|
||||
});
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'../model/quote',
|
||||
'Magento_Checkout/js/model/resource-url-manager',
|
||||
'Magento_Checkout/js/model/error-processor',
|
||||
'mage/storage',
|
||||
'Magento_Checkout/js/model/totals'
|
||||
], function ($, quote, resourceUrlManager, errorProcessor, storage, totals) {
|
||||
'use strict';
|
||||
|
||||
return function (callbacks, deferred) {
|
||||
deferred = deferred || $.Deferred();
|
||||
totals.isLoading(true);
|
||||
|
||||
return storage.get(
|
||||
resourceUrlManager.getUrlForCartTotals(quote),
|
||||
false
|
||||
).done(function (response) {
|
||||
var proceed = true;
|
||||
|
||||
totals.isLoading(false);
|
||||
|
||||
if (callbacks.length > 0) {
|
||||
$.each(callbacks, function (index, callback) {
|
||||
proceed = proceed && callback();
|
||||
});
|
||||
}
|
||||
|
||||
if (proceed) {
|
||||
quote.setTotals(response);
|
||||
deferred.resolve();
|
||||
}
|
||||
}).fail(function (response) {
|
||||
totals.isLoading(false);
|
||||
deferred.reject();
|
||||
errorProcessor.process(response);
|
||||
}).always(function () {
|
||||
totals.isLoading(false);
|
||||
});
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/url-builder',
|
||||
'Magento_Customer/js/model/customer',
|
||||
'Magento_Checkout/js/model/place-order'
|
||||
], function (quote, urlBuilder, customer, placeOrderService) {
|
||||
'use strict';
|
||||
|
||||
return function (paymentData, messageContainer) {
|
||||
var serviceUrl, payload;
|
||||
|
||||
payload = {
|
||||
cartId: quote.getQuoteId(),
|
||||
billingAddress: quote.billingAddress(),
|
||||
paymentMethod: paymentData
|
||||
};
|
||||
|
||||
if (customer.isLoggedIn()) {
|
||||
serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
|
||||
} else {
|
||||
serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payment-information', {
|
||||
quoteId: quote.getQuoteId()
|
||||
});
|
||||
payload.email = quote.guestEmail;
|
||||
}
|
||||
|
||||
return placeOrderService(serviceUrl, payload, messageContainer);
|
||||
};
|
||||
});
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/action/select-shipping-address',
|
||||
'Magento_Checkout/js/model/shipping-rate-registry'
|
||||
], function (quote, selectShippingAddress, rateRegistry) {
|
||||
'use strict';
|
||||
|
||||
return function () {
|
||||
var shippingAddress = null;
|
||||
|
||||
if (!quote.isVirtual()) {
|
||||
shippingAddress = quote.shippingAddress();
|
||||
|
||||
rateRegistry.set(shippingAddress.getCacheKey(), null);
|
||||
selectShippingAddress(shippingAddress);
|
||||
}
|
||||
};
|
||||
});
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define(
|
||||
[
|
||||
'mage/url',
|
||||
'Magento_Checkout/js/model/full-screen-loader'
|
||||
],
|
||||
function (url, fullScreenLoader) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
redirectUrl: window.checkoutConfig.defaultSuccessPageUrl,
|
||||
|
||||
/**
|
||||
* Provide redirect to page
|
||||
*/
|
||||
execute: function () {
|
||||
fullScreenLoader.startLoader();
|
||||
this.redirectToSuccessPage();
|
||||
},
|
||||
|
||||
/**
|
||||
* Redirect to success page.
|
||||
*/
|
||||
redirectToSuccessPage: function () {
|
||||
window.location.replace(url.build(this.redirectUrl));
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'../model/quote'
|
||||
], function ($, quote) {
|
||||
'use strict';
|
||||
|
||||
return function (billingAddress) {
|
||||
var address = null;
|
||||
|
||||
if (quote.shippingAddress() && billingAddress.getCacheKey() == //eslint-disable-line eqeqeq
|
||||
quote.shippingAddress().getCacheKey()
|
||||
) {
|
||||
address = $.extend(true, {}, billingAddress);
|
||||
address.saveInAddressBook = null;
|
||||
} else {
|
||||
address = billingAddress;
|
||||
}
|
||||
quote.billingAddress(address);
|
||||
};
|
||||
});
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'Magento_Checkout/js/model/quote'
|
||||
], function (quote) {
|
||||
'use strict';
|
||||
|
||||
return function (paymentMethod) {
|
||||
if (paymentMethod) {
|
||||
paymentMethod.__disableTmpl = {
|
||||
title: true
|
||||
};
|
||||
}
|
||||
quote.paymentMethod(paymentMethod);
|
||||
};
|
||||
});
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'Magento_Checkout/js/model/quote'
|
||||
], function (quote) {
|
||||
'use strict';
|
||||
|
||||
return function (shippingAddress) {
|
||||
quote.shippingAddress(shippingAddress);
|
||||
};
|
||||
});
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'../model/quote'
|
||||
], function (quote) {
|
||||
'use strict';
|
||||
|
||||
return function (shippingMethod) {
|
||||
quote.shippingMethod(shippingMethod);
|
||||
};
|
||||
});
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define(
|
||||
[
|
||||
'jquery',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/url-builder',
|
||||
'mage/storage',
|
||||
'Magento_Checkout/js/model/error-processor',
|
||||
'Magento_Customer/js/model/customer',
|
||||
'Magento_Checkout/js/model/full-screen-loader',
|
||||
'Magento_Checkout/js/action/get-payment-information'
|
||||
],
|
||||
function ($,
|
||||
quote,
|
||||
urlBuilder,
|
||||
storage,
|
||||
errorProcessor,
|
||||
customer,
|
||||
fullScreenLoader,
|
||||
getPaymentInformationAction
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
return function (messageContainer) {
|
||||
var serviceUrl,
|
||||
payload;
|
||||
|
||||
/**
|
||||
* Checkout for guest and registered customer.
|
||||
*/
|
||||
if (!customer.isLoggedIn()) {
|
||||
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/billing-address', {
|
||||
cartId: quote.getQuoteId()
|
||||
});
|
||||
payload = {
|
||||
cartId: quote.getQuoteId(),
|
||||
address: quote.billingAddress()
|
||||
};
|
||||
} else {
|
||||
serviceUrl = urlBuilder.createUrl('/carts/mine/billing-address', {});
|
||||
payload = {
|
||||
cartId: quote.getQuoteId(),
|
||||
address: quote.billingAddress()
|
||||
};
|
||||
}
|
||||
|
||||
fullScreenLoader.startLoader();
|
||||
|
||||
return storage.post(
|
||||
serviceUrl, JSON.stringify(payload)
|
||||
).done(
|
||||
function () {
|
||||
var deferred = $.Deferred();
|
||||
|
||||
getPaymentInformationAction(deferred);
|
||||
$.when(deferred).done(function () {
|
||||
fullScreenLoader.stopLoader();
|
||||
});
|
||||
}
|
||||
).fail(
|
||||
function (response) {
|
||||
errorProcessor.process(response, messageContainer);
|
||||
fullScreenLoader.stopLoader();
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/url-builder',
|
||||
'mage/storage',
|
||||
'Magento_Checkout/js/model/error-processor',
|
||||
'Magento_Customer/js/model/customer',
|
||||
'Magento_Checkout/js/action/get-totals',
|
||||
'Magento_Checkout/js/model/full-screen-loader',
|
||||
'underscore',
|
||||
'Magento_Checkout/js/model/payment/place-order-hooks'
|
||||
], function (quote, urlBuilder, storage, errorProcessor, customer, getTotalsAction, fullScreenLoader, _, hooks) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Filter template data.
|
||||
*
|
||||
* @param {Object|Array} data
|
||||
*/
|
||||
var filterTemplateData = function (data) {
|
||||
return _.each(data, function (value, key, list) {
|
||||
if (_.isArray(value) || _.isObject(value)) {
|
||||
list[key] = filterTemplateData(value);
|
||||
}
|
||||
|
||||
if (key === '__disableTmpl' || key === 'title') {
|
||||
delete list[key];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return function (messageContainer, paymentData, skipBilling) {
|
||||
var serviceUrl,
|
||||
payload,
|
||||
headers = {};
|
||||
|
||||
paymentData = filterTemplateData(paymentData);
|
||||
skipBilling = skipBilling || false;
|
||||
payload = {
|
||||
cartId: quote.getQuoteId(),
|
||||
paymentMethod: paymentData
|
||||
};
|
||||
|
||||
/**
|
||||
* Checkout for guest and registered customer.
|
||||
*/
|
||||
if (!customer.isLoggedIn()) {
|
||||
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/set-payment-information', {
|
||||
cartId: quote.getQuoteId()
|
||||
});
|
||||
payload.email = quote.guestEmail;
|
||||
} else {
|
||||
serviceUrl = urlBuilder.createUrl('/carts/mine/set-payment-information', {});
|
||||
}
|
||||
|
||||
if (skipBilling === false) {
|
||||
payload.billingAddress = quote.billingAddress();
|
||||
}
|
||||
|
||||
fullScreenLoader.startLoader();
|
||||
|
||||
_.each(hooks.requestModifiers, function (modifier) {
|
||||
modifier(headers, payload);
|
||||
});
|
||||
|
||||
return storage.post(
|
||||
serviceUrl, JSON.stringify(payload), true, 'application/json', headers
|
||||
).fail(
|
||||
function (response) {
|
||||
errorProcessor.process(response, messageContainer);
|
||||
}
|
||||
).always(
|
||||
function () {
|
||||
fullScreenLoader.stopLoader();
|
||||
_.each(hooks.afterRequestListeners, function (listener) {
|
||||
listener();
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
});
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'Magento_Checkout/js/action/set-payment-information-extended'
|
||||
|
||||
], function (setPaymentInformationExtended) {
|
||||
'use strict';
|
||||
|
||||
return function (messageContainer, paymentData) {
|
||||
|
||||
return setPaymentInformationExtended(messageContainer, paymentData, false);
|
||||
};
|
||||
});
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'../model/quote',
|
||||
'Magento_Checkout/js/model/shipping-save-processor'
|
||||
], function (quote, shippingSaveProcessor) {
|
||||
'use strict';
|
||||
|
||||
return function () {
|
||||
return shippingSaveProcessor.saveShippingInformation(quote.shippingAddress().getType());
|
||||
};
|
||||
});
|
||||
+203
@@ -0,0 +1,203 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'Magento_Ui/js/modal/alert',
|
||||
'Magento_Ui/js/modal/confirm',
|
||||
'jquery',
|
||||
'mage/translate',
|
||||
'jquery-ui-modules/widget',
|
||||
'mage/validation'
|
||||
], function (alert, confirm, $, $t) {
|
||||
'use strict';
|
||||
|
||||
$.widget('mage.updateShoppingCart', {
|
||||
options: {
|
||||
validationURL: '',
|
||||
eventName: 'updateCartItemQty',
|
||||
updateCartActionContainer: '',
|
||||
isCartHasUpdatedContent: false
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
_create: function () {
|
||||
this._on(this.element, {
|
||||
'submit': this.onSubmit
|
||||
});
|
||||
this._on('[data-role=cart-item-qty]', {
|
||||
'change': function () {
|
||||
this.isCartHasUpdatedContent = true;
|
||||
}
|
||||
});
|
||||
this._on('ul.pages-items', {
|
||||
'click a': function (event) {
|
||||
if (this.isCartHasUpdatedContent) {
|
||||
event.preventDefault();
|
||||
this.changePageConfirm($(event.currentTarget).attr('href'));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Show the confirmation popup
|
||||
* @param nextPageUrl
|
||||
*/
|
||||
changePageConfirm: function (nextPageUrl) {
|
||||
confirm({
|
||||
title: $t('Are you sure you want to leave the page?'),
|
||||
content: $t('Changes you made to the cart will not be saved.'),
|
||||
actions: {
|
||||
confirm: function () {
|
||||
window.location.href = nextPageUrl;
|
||||
}
|
||||
},
|
||||
buttons: [{
|
||||
text: $t('Cancel'),
|
||||
class: 'action-secondary action-dismiss',
|
||||
click: function (event) {
|
||||
this.closeModal(event);
|
||||
}
|
||||
}, {
|
||||
text: $t('Leave'),
|
||||
class: 'action-primary action-accept',
|
||||
click: function (event) {
|
||||
this.closeModal(event, true);
|
||||
}
|
||||
}]
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Prevents default submit action and calls form validator.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @return {Boolean}
|
||||
*/
|
||||
onSubmit: function (event) {
|
||||
var action = this.element.find(this.options.updateCartActionContainer).val();
|
||||
|
||||
if (!this.options.validationURL || action === 'empty_cart') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.isValid()) {
|
||||
event.preventDefault();
|
||||
this.validateItems(this.options.validationURL, this.element.serialize());
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Validates requested form.
|
||||
*
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isValid: function () {
|
||||
return this.element.validation() && this.element.validation('isValid');
|
||||
},
|
||||
|
||||
/**
|
||||
* Validates updated shopping cart data.
|
||||
*
|
||||
* @param {String} url - request url
|
||||
* @param {Object} data - post data for ajax call
|
||||
*/
|
||||
validateItems: function (url, data) {
|
||||
$.extend(data, {
|
||||
'form_key': $.mage.cookies.get('form_key')
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: data,
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
context: this,
|
||||
|
||||
/** @inheritdoc */
|
||||
beforeSend: function () {
|
||||
$(document.body).trigger('processStart');
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
complete: function () {
|
||||
$(document.body).trigger('processStop');
|
||||
}
|
||||
})
|
||||
.done(function (response) {
|
||||
if (response.success) {
|
||||
this.onSuccess();
|
||||
} else {
|
||||
this.onError(response);
|
||||
}
|
||||
})
|
||||
.fail(function () {
|
||||
this.submitForm();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Form validation succeed.
|
||||
*/
|
||||
onSuccess: function () {
|
||||
$(document).trigger('ajax:' + this.options.eventName);
|
||||
this.submitForm();
|
||||
},
|
||||
|
||||
/**
|
||||
* Form validation failed.
|
||||
*/
|
||||
onError: function (response) {
|
||||
var that = this,
|
||||
elm,
|
||||
responseData = [];
|
||||
|
||||
try {
|
||||
responseData = JSON.parse(response['error_message']);
|
||||
} catch (error) {
|
||||
}
|
||||
|
||||
if (response['error_message']) {
|
||||
try {
|
||||
$.each(responseData, function (index, data) {
|
||||
|
||||
if (data.itemId !== undefined) {
|
||||
elm = $('#cart-' + data.itemId + '-qty');
|
||||
elm.val(elm.attr('data-item-qty'));
|
||||
}
|
||||
response['error_message'] = data.error;
|
||||
});
|
||||
} catch (e) {}
|
||||
alert({
|
||||
content: response['error_message'],
|
||||
actions: {
|
||||
/** @inheritdoc */
|
||||
always: function () {
|
||||
that.submitForm();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.submitForm();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Real submit of validated form.
|
||||
*/
|
||||
submitForm: function () {
|
||||
this.element
|
||||
.off('submit', this.onSubmit)
|
||||
.on('submit', function () {
|
||||
$(document.body).trigger('processStart');
|
||||
})
|
||||
.trigger('submit');
|
||||
}
|
||||
});
|
||||
|
||||
return $.mage.updateShoppingCart;
|
||||
});
|
||||
@@ -0,0 +1,300 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checkout adapter for customer data storage
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Customer/js/customer-data',
|
||||
'mageUtils',
|
||||
'jquery/jquery-storageapi'
|
||||
], function ($, storage, utils) {
|
||||
'use strict';
|
||||
|
||||
var cacheKey = 'checkout-data',
|
||||
|
||||
/**
|
||||
* @param {Object} data
|
||||
*/
|
||||
saveData = function (data) {
|
||||
storage.set(cacheKey, data);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
initData = function () {
|
||||
return {
|
||||
'selectedShippingAddress': null, //Selected shipping address pulled from persistence storage
|
||||
'shippingAddressFromData': null, //Shipping address pulled from persistence storage
|
||||
'newCustomerShippingAddress': null, //Shipping address pulled from persistence storage for customer
|
||||
'selectedShippingRate': null, //Shipping rate pulled from persistence storage
|
||||
'selectedPaymentMethod': null, //Payment method pulled from persistence storage
|
||||
'selectedBillingAddress': null, //Selected billing address pulled from persistence storage
|
||||
'billingAddressFromData': null, //Billing address pulled from persistence storage
|
||||
'newCustomerBillingAddress': null //Billing address pulled from persistence storage for new customer
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getData = function () {
|
||||
var data = storage.get(cacheKey)();
|
||||
|
||||
if ($.isEmptyObject(data)) {
|
||||
data = $.initNamespaceStorage('mage-cache-storage').localStorage.get(cacheKey);
|
||||
|
||||
if ($.isEmptyObject(data)) {
|
||||
data = initData();
|
||||
saveData(data);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
return {
|
||||
/**
|
||||
* Setting the selected shipping address pulled from persistence storage
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
setSelectedShippingAddress: function (data) {
|
||||
var obj = getData();
|
||||
|
||||
obj.selectedShippingAddress = data;
|
||||
saveData(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the selected shipping address from persistence storage
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getSelectedShippingAddress: function () {
|
||||
return getData().selectedShippingAddress;
|
||||
},
|
||||
|
||||
/**
|
||||
* Setting the shipping address pulled from persistence storage
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
setShippingAddressFromData: function (data) {
|
||||
var obj = getData();
|
||||
|
||||
obj.shippingAddressFromData = utils.filterFormData(data);
|
||||
saveData(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the shipping address from persistence storage
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getShippingAddressFromData: function () {
|
||||
return getData().shippingAddressFromData;
|
||||
},
|
||||
|
||||
/**
|
||||
* Setting the shipping address pulled from persistence storage for new customer
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
setNewCustomerShippingAddress: function (data) {
|
||||
var obj = getData();
|
||||
|
||||
obj.newCustomerShippingAddress = data;
|
||||
saveData(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the shipping address from persistence storage for new customer
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getNewCustomerShippingAddress: function () {
|
||||
return getData().newCustomerShippingAddress;
|
||||
},
|
||||
|
||||
/**
|
||||
* Setting the selected shipping rate pulled from persistence storage
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
setSelectedShippingRate: function (data) {
|
||||
var obj = getData();
|
||||
|
||||
obj.selectedShippingRate = data;
|
||||
saveData(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the selected shipping rate from local storage
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getSelectedShippingRate: function () {
|
||||
return getData().selectedShippingRate;
|
||||
},
|
||||
|
||||
/**
|
||||
* Setting the selected payment method pulled from persistence storage
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
setSelectedPaymentMethod: function (data) {
|
||||
var obj = getData();
|
||||
|
||||
obj.selectedPaymentMethod = data;
|
||||
saveData(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the payment method from persistence storage
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getSelectedPaymentMethod: function () {
|
||||
return getData().selectedPaymentMethod;
|
||||
},
|
||||
|
||||
/**
|
||||
* Setting the selected billing address pulled from persistence storage
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
setSelectedBillingAddress: function (data) {
|
||||
var obj = getData();
|
||||
|
||||
obj.selectedBillingAddress = data;
|
||||
saveData(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the selected billing address from persistence storage
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getSelectedBillingAddress: function () {
|
||||
return getData().selectedBillingAddress;
|
||||
},
|
||||
|
||||
/**
|
||||
* Setting the billing address pulled from persistence storage
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
setBillingAddressFromData: function (data) {
|
||||
var obj = getData();
|
||||
|
||||
obj.billingAddressFromData = utils.filterFormData(data);
|
||||
saveData(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the billing address from persistence storage
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getBillingAddressFromData: function () {
|
||||
return getData().billingAddressFromData;
|
||||
},
|
||||
|
||||
/**
|
||||
* Setting the billing address pulled from persistence storage for new customer
|
||||
*
|
||||
* @param {Object} data
|
||||
*/
|
||||
setNewCustomerBillingAddress: function (data) {
|
||||
var obj = getData();
|
||||
|
||||
obj.newCustomerBillingAddress = data;
|
||||
saveData(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the billing address from persistence storage for new customer
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getNewCustomerBillingAddress: function () {
|
||||
return getData().newCustomerBillingAddress;
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the email address from persistence storage
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getValidatedEmailValue: function () {
|
||||
var obj = getData();
|
||||
|
||||
return obj.validatedEmailValue ? obj.validatedEmailValue : '';
|
||||
},
|
||||
|
||||
/**
|
||||
* Setting the email address pulled from persistence storage
|
||||
*
|
||||
* @param {String} email
|
||||
*/
|
||||
setValidatedEmailValue: function (email) {
|
||||
var obj = getData();
|
||||
|
||||
obj.validatedEmailValue = email;
|
||||
saveData(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the email input field value from persistence storage
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getInputFieldEmailValue: function () {
|
||||
var obj = getData();
|
||||
|
||||
return obj.inputFieldEmailValue ? obj.inputFieldEmailValue : '';
|
||||
},
|
||||
|
||||
/**
|
||||
* Setting the email input field value pulled from persistence storage
|
||||
*
|
||||
* @param {String} email
|
||||
*/
|
||||
setInputFieldEmailValue: function (email) {
|
||||
var obj = getData();
|
||||
|
||||
obj.inputFieldEmailValue = email;
|
||||
saveData(obj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pulling the checked email value from persistence storage
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getCheckedEmailValue: function () {
|
||||
var obj = getData();
|
||||
|
||||
return obj.checkedEmailValue ? obj.checkedEmailValue : '';
|
||||
},
|
||||
|
||||
/**
|
||||
* Setting the checked email value pulled from persistence storage
|
||||
*
|
||||
* @param {String} email
|
||||
*/
|
||||
setCheckedEmailValue: function (email) {
|
||||
var obj = getData();
|
||||
|
||||
obj.checkedEmailValue = email;
|
||||
saveData(obj);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
define([
|
||||
'rjsResolver'
|
||||
], function (resolver) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Removes provided loader element from DOM.
|
||||
*
|
||||
* @param {HTMLElement} $loader - Loader DOM element.
|
||||
*/
|
||||
function hideLoader($loader) {
|
||||
$loader.parentNode.removeChild($loader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes assets loading process listener.
|
||||
*
|
||||
* @param {Object} config - Optional configuration
|
||||
* @param {HTMLElement} $loader - Loader DOM element.
|
||||
*/
|
||||
function init(config, $loader) {
|
||||
resolver(hideLoader.bind(null, $loader));
|
||||
}
|
||||
|
||||
return init;
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'jquery-ui-modules/widget'
|
||||
], function ($) {
|
||||
'use strict';
|
||||
|
||||
$.widget('mage.discountCode', {
|
||||
options: {
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
_create: function () {
|
||||
this.couponCode = $(this.options.couponCodeSelector);
|
||||
this.removeCoupon = $(this.options.removeCouponSelector);
|
||||
|
||||
$(this.options.applyButton).on('click', $.proxy(function () {
|
||||
this.couponCode.attr('data-validate', '{required:true}');
|
||||
this.removeCoupon.attr('value', '0');
|
||||
$(this.element).validation().trigger('submit');
|
||||
}, this));
|
||||
|
||||
$(this.options.cancelButton).on('click', $.proxy(function () {
|
||||
this.couponCode.removeAttr('data-validate');
|
||||
this.removeCoupon.attr('value', '1');
|
||||
this.element.trigger('submit');
|
||||
}, this));
|
||||
}
|
||||
});
|
||||
|
||||
return $.mage.discountCode;
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define(['Magento_Customer/js/customer-data'], function (customerData) {
|
||||
'use strict';
|
||||
|
||||
return function () {
|
||||
var cartData = customerData.get('cart');
|
||||
|
||||
customerData.getInitCustomerData().done(function () {
|
||||
if (cartData().items && cartData().items.length !== 0) {
|
||||
customerData.reload(['cart'], false);
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Checkout/js/model/new-customer-address',
|
||||
'Magento_Customer/js/customer-data',
|
||||
'mage/utils/objects',
|
||||
'underscore'
|
||||
], function ($, address, customerData, mageUtils, _) {
|
||||
'use strict';
|
||||
|
||||
var countryData = customerData.get('directory-data');
|
||||
|
||||
return {
|
||||
/**
|
||||
* Convert address form data to Address object
|
||||
*
|
||||
* @param {Object} formData
|
||||
* @returns {Object}
|
||||
*/
|
||||
formAddressDataToQuoteAddress: function (formData) {
|
||||
// clone address form data to new object
|
||||
var addressData = $.extend(true, {}, formData),
|
||||
region,
|
||||
regionName = addressData.region,
|
||||
customAttributes;
|
||||
|
||||
if (mageUtils.isObject(addressData.street)) {
|
||||
addressData.street = this.objectToArray(addressData.street);
|
||||
}
|
||||
|
||||
addressData.region = {
|
||||
'region_id': addressData['region_id'],
|
||||
'region_code': addressData['region_code'],
|
||||
region: regionName
|
||||
};
|
||||
|
||||
if (addressData['region_id'] &&
|
||||
countryData()[addressData['country_id']] &&
|
||||
countryData()[addressData['country_id']].regions
|
||||
) {
|
||||
region = countryData()[addressData['country_id']].regions[addressData['region_id']];
|
||||
|
||||
if (region) {
|
||||
addressData.region['region_id'] = addressData['region_id'];
|
||||
addressData.region['region_code'] = region.code;
|
||||
addressData.region.region = region.name;
|
||||
}
|
||||
} else if (
|
||||
!addressData['region_id'] &&
|
||||
countryData()[addressData['country_id']] &&
|
||||
countryData()[addressData['country_id']].regions
|
||||
) {
|
||||
addressData.region['region_code'] = '';
|
||||
addressData.region.region = '';
|
||||
}
|
||||
delete addressData['region_id'];
|
||||
|
||||
if (addressData['custom_attributes']) {
|
||||
addressData['custom_attributes'] = _.map(
|
||||
addressData['custom_attributes'],
|
||||
function (value, key) {
|
||||
customAttributes = {
|
||||
'attribute_code': key,
|
||||
'value': value
|
||||
};
|
||||
|
||||
if (typeof value === 'boolean') {
|
||||
customAttributes = {
|
||||
'attribute_code': key,
|
||||
'value': value,
|
||||
'label': value === true ? 'Yes' : 'No'
|
||||
};
|
||||
}
|
||||
|
||||
return customAttributes;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return address(addressData);
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert Address object to address form data.
|
||||
*
|
||||
* @param {Object} addrs
|
||||
* @returns {Object}
|
||||
*/
|
||||
quoteAddressToFormAddressData: function (addrs) {
|
||||
var self = this,
|
||||
output = {},
|
||||
streetObject,
|
||||
customAttributesObject;
|
||||
|
||||
$.each(addrs, function (key) {
|
||||
if (addrs.hasOwnProperty(key) && typeof addrs[key] !== 'function') {
|
||||
output[self.toUnderscore(key)] = addrs[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (Array.isArray(addrs.street)) {
|
||||
streetObject = {};
|
||||
addrs.street.forEach(function (value, index) {
|
||||
streetObject[index] = value;
|
||||
});
|
||||
output.street = streetObject;
|
||||
}
|
||||
|
||||
//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
if (Array.isArray(addrs.customAttributes)) {
|
||||
customAttributesObject = {};
|
||||
addrs.customAttributes.forEach(function (value) {
|
||||
customAttributesObject[value.attribute_code] = value.value;
|
||||
});
|
||||
output.custom_attributes = customAttributesObject;
|
||||
}
|
||||
//jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
|
||||
return output;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} string
|
||||
*/
|
||||
toUnderscore: function (string) {
|
||||
return string.replace(/([A-Z])/g, function ($1) {
|
||||
return '_' + $1.toLowerCase();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} formProviderData
|
||||
* @param {String} formIndex
|
||||
* @return {Object}
|
||||
*/
|
||||
formDataProviderToFlatData: function (formProviderData, formIndex) {
|
||||
var addressData = {};
|
||||
|
||||
$.each(formProviderData, function (path, value) {
|
||||
var pathComponents = path.split('.'),
|
||||
dataObject = {};
|
||||
|
||||
pathComponents.splice(pathComponents.indexOf(formIndex), 1);
|
||||
pathComponents.reverse();
|
||||
$.each(pathComponents, function (index, pathPart) {
|
||||
var parent = {};
|
||||
|
||||
if (index == 0) { //eslint-disable-line eqeqeq
|
||||
dataObject[pathPart] = value;
|
||||
} else {
|
||||
parent[pathPart] = dataObject;
|
||||
dataObject = parent;
|
||||
}
|
||||
});
|
||||
$.extend(true, addressData, dataObject);
|
||||
});
|
||||
|
||||
return addressData;
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert object to array
|
||||
* @param {Object} object
|
||||
* @returns {Array}
|
||||
*/
|
||||
objectToArray: function (object) {
|
||||
var convertedArray = [];
|
||||
|
||||
$.each(object, function (key) {
|
||||
return typeof object[key] === 'string' ? convertedArray.push(object[key]) : false;
|
||||
});
|
||||
|
||||
return convertedArray.slice(0);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} addrs
|
||||
* @return {*|Object}
|
||||
*/
|
||||
addressToEstimationAddress: function (addrs) {
|
||||
var self = this,
|
||||
estimatedAddressData = {};
|
||||
|
||||
$.each(addrs, function (key) {
|
||||
estimatedAddressData[self.toUnderscore(key)] = addrs[key];
|
||||
});
|
||||
|
||||
return this.formAddressDataToQuoteAddress(estimatedAddressData);
|
||||
}
|
||||
};
|
||||
});
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'ko',
|
||||
'Magento_Ui/js/model/messages'
|
||||
], function (ko, Messages) {
|
||||
'use strict';
|
||||
|
||||
return new Messages();
|
||||
});
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Checkout/js/model/postcode-validator',
|
||||
'mage/translate',
|
||||
'uiRegistry'
|
||||
], function (
|
||||
$,
|
||||
postcodeValidator,
|
||||
$t,
|
||||
uiRegistry
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
var postcodeElementName = 'postcode';
|
||||
|
||||
return {
|
||||
validateZipCodeTimeout: 0,
|
||||
validateDelay: 2000,
|
||||
|
||||
/**
|
||||
* Perform postponed binding for fieldset elements
|
||||
*
|
||||
* @param {String} formPath
|
||||
*/
|
||||
initFields: function (formPath) {
|
||||
var self = this;
|
||||
|
||||
uiRegistry.async(formPath + '.' + postcodeElementName)(self.bindHandler.bind(self));
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} element
|
||||
* @param {Number} delay
|
||||
*/
|
||||
bindHandler: function (element, delay) {
|
||||
var self = this;
|
||||
|
||||
delay = typeof delay === 'undefined' ? self.validateDelay : delay;
|
||||
|
||||
element.on('value', function () {
|
||||
clearTimeout(self.validateZipCodeTimeout);
|
||||
self.validateZipCodeTimeout = setTimeout(function () {
|
||||
self.postcodeValidation(element);
|
||||
}, delay);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} postcodeElement
|
||||
* @return {*}
|
||||
*/
|
||||
postcodeValidation: function (postcodeElement) {
|
||||
var countryId = $('select[name="country_id"]:visible').val(),
|
||||
validationResult,
|
||||
warnMessage;
|
||||
|
||||
if (postcodeElement == null || postcodeElement.value() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
postcodeElement.warn(null);
|
||||
validationResult = postcodeValidator.validate(postcodeElement.value(), countryId);
|
||||
|
||||
if (!validationResult) {
|
||||
warnMessage = $t('Provided Zip/Postal Code seems to be invalid.');
|
||||
|
||||
if (postcodeValidator.validatedPostCodeExample.length) {
|
||||
warnMessage += $t(' Example: ') + postcodeValidator.validatedPostCodeExample.join('; ') + '. ';
|
||||
}
|
||||
warnMessage += $t('If you believe it is the right one you can ignore this notice.');
|
||||
postcodeElement.warn(warnMessage);
|
||||
}
|
||||
|
||||
return validationResult;
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Cart adapter for customer data storage.
|
||||
* It stores cart data in customer data(localStorage) without saving on server.
|
||||
* Adapter is created for shipping rates and totals data caching. It eliminates unneeded calculations requests.
|
||||
*/
|
||||
define([
|
||||
'underscore',
|
||||
'Magento_Customer/js/customer-data',
|
||||
'mageUtils'
|
||||
], function (_, storage, utils) {
|
||||
'use strict';
|
||||
|
||||
var cacheKey = 'cart-data',
|
||||
cartData = {
|
||||
totals: null,
|
||||
address: null,
|
||||
cartVersion: null,
|
||||
shippingMethodCode: null,
|
||||
shippingCarrierCode: null,
|
||||
rates: null
|
||||
},
|
||||
|
||||
/**
|
||||
* Set data to local storage.
|
||||
*
|
||||
* @param {Object} checkoutData
|
||||
*/
|
||||
setData = function (checkoutData) {
|
||||
storage.set(cacheKey, checkoutData);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get data from local storage.
|
||||
*
|
||||
* @param {String} [key]
|
||||
* @returns {*}
|
||||
*/
|
||||
getData = function (key) {
|
||||
var data = key ? storage.get(cacheKey)()[key] : storage.get(cacheKey)();
|
||||
|
||||
if (_.isEmpty(storage.get(cacheKey)())) {
|
||||
setData(utils.copy(cartData));
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Build method name base on name, prefix and suffix.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {String} prefix
|
||||
* @param {String} suffix
|
||||
* @return {String}
|
||||
*/
|
||||
getMethodName = function (name, prefix, suffix) {
|
||||
prefix = prefix || '';
|
||||
suffix = suffix || '';
|
||||
|
||||
return prefix + name.charAt(0).toUpperCase() + name.slice(1) + suffix;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides get/set/isChanged/clear methods for work with cart data.
|
||||
* Can be customized via mixin functionality.
|
||||
*/
|
||||
return {
|
||||
cartData: cartData,
|
||||
|
||||
/**
|
||||
* Array of required address fields
|
||||
*/
|
||||
requiredFields: ['countryId', 'region', 'regionId', 'postcode'],
|
||||
|
||||
/**
|
||||
* Get data from customer data.
|
||||
* Concatenate provided key with method name and call method if it exist or makes get by key.
|
||||
*
|
||||
* @param {String} key
|
||||
* @return {*}
|
||||
*/
|
||||
get: function (key) {
|
||||
var methodName = getMethodName(key, '_get');
|
||||
|
||||
if (key === cacheKey) {
|
||||
return getData();
|
||||
}
|
||||
|
||||
if (this[methodName]) {
|
||||
return this[methodName]();
|
||||
}
|
||||
|
||||
return getData(key);
|
||||
},
|
||||
|
||||
/**
|
||||
* Set data to customer data.
|
||||
* Concatenate provided key with method name and call method if it exist or makes set by key.
|
||||
* @example _setCustomAddress method will be called, if it exists.
|
||||
* set('address', customAddressValue)
|
||||
* @example Will set value by provided key.
|
||||
* set('rates', ratesToCompare)
|
||||
*
|
||||
* @param {String} key
|
||||
* @param {*} value
|
||||
*/
|
||||
set: function (key, value) {
|
||||
var methodName = getMethodName(key, '_set'),
|
||||
obj;
|
||||
|
||||
if (key === cacheKey) {
|
||||
_.each(value, function (val, k) {
|
||||
this.set(k, val);
|
||||
}, this);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this[methodName]) {
|
||||
this[methodName](value);
|
||||
} else {
|
||||
obj = getData();
|
||||
obj[key] = value;
|
||||
setData(obj);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear data in cache.
|
||||
* Concatenate provided key with method name and call method if it exist or clear by key.
|
||||
* @example _clearCustomAddress method will be called, if it exist.
|
||||
* clear('customAddress')
|
||||
* @example Will clear data by provided key.
|
||||
* clear('rates')
|
||||
*
|
||||
* @param {String} key
|
||||
*/
|
||||
clear: function (key) {
|
||||
var methodName = getMethodName(key, '_clear');
|
||||
|
||||
if (key === cacheKey) {
|
||||
setData(this.cartData);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this[methodName]) {
|
||||
this[methodName]();
|
||||
} else {
|
||||
this.set(key, null);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if provided data has difference with cached data.
|
||||
* Concatenate provided key with method name and call method if it exist or makes strict equality.
|
||||
* @example Will call existing _isAddressChanged.
|
||||
* isChanged('address', addressToCompare)
|
||||
* @example Will get data by provided key and make strict equality with provided value.
|
||||
* isChanged('rates', ratesToCompare)
|
||||
*
|
||||
* @param {String} key
|
||||
* @param {*} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isChanged: function (key, value) {
|
||||
var methodName = getMethodName(key, '_is', 'Changed');
|
||||
|
||||
if (this[methodName]) {
|
||||
return this[methodName](value);
|
||||
}
|
||||
|
||||
return this.get(key) !== value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Compare cached address with provided.
|
||||
* Custom method for check object equality.
|
||||
*
|
||||
* @param {Object} address
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
_isAddressChanged: function (address) {
|
||||
return JSON.stringify(_.pick(this.get('address'), this.requiredFields)) !==
|
||||
JSON.stringify(_.pick(address, this.requiredFields));
|
||||
},
|
||||
|
||||
/**
|
||||
* Compare cached subtotal with provided.
|
||||
* Custom method for check object equality.
|
||||
*
|
||||
* @param {float} subtotal
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
_isSubtotalChanged: function (subtotal) {
|
||||
var cached = parseFloat(this.get('totals').subtotal);
|
||||
|
||||
return subtotal !== cached;
|
||||
}
|
||||
};
|
||||
});
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/shipping-rate-processor/new-address',
|
||||
'Magento_Checkout/js/model/cart/totals-processor/default',
|
||||
'Magento_Checkout/js/model/shipping-service',
|
||||
'Magento_Checkout/js/model/cart/cache',
|
||||
'Magento_Customer/js/customer-data'
|
||||
], function (quote, defaultProcessor, totalsDefaultProvider, shippingService, cartCache, customerData) {
|
||||
'use strict';
|
||||
|
||||
var rateProcessors = {},
|
||||
totalsProcessors = {},
|
||||
|
||||
/**
|
||||
* Estimate totals for shipping address and update shipping rates.
|
||||
*/
|
||||
estimateTotalsAndUpdateRates = function () {
|
||||
var type = quote.shippingAddress().getType();
|
||||
|
||||
if (
|
||||
quote.isVirtual() ||
|
||||
window.checkoutConfig.activeCarriers && window.checkoutConfig.activeCarriers.length === 0
|
||||
) {
|
||||
// update totals block when estimated address was set
|
||||
totalsProcessors['default'] = totalsDefaultProvider;
|
||||
totalsProcessors[type] ?
|
||||
totalsProcessors[type].estimateTotals(quote.shippingAddress()) :
|
||||
totalsProcessors['default'].estimateTotals(quote.shippingAddress());
|
||||
} else {
|
||||
// check if user data not changed -> load rates from cache
|
||||
if (!cartCache.isChanged('address', quote.shippingAddress()) &&
|
||||
!cartCache.isChanged('cartVersion', customerData.get('cart')()['data_id']) &&
|
||||
cartCache.get('rates')
|
||||
) {
|
||||
shippingService.setShippingRates(cartCache.get('rates'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// update rates list when estimated address was set
|
||||
rateProcessors['default'] = defaultProcessor;
|
||||
rateProcessors[type] ?
|
||||
rateProcessors[type].getRates(quote.shippingAddress()) :
|
||||
rateProcessors['default'].getRates(quote.shippingAddress());
|
||||
|
||||
// save rates to cache after load
|
||||
shippingService.getShippingRates().subscribe(function (rates) {
|
||||
cartCache.set('rates', rates);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Estimate totals for shipping address.
|
||||
*/
|
||||
estimateTotalsShipping = function () {
|
||||
totalsDefaultProvider.estimateTotals(quote.shippingAddress());
|
||||
},
|
||||
|
||||
/**
|
||||
* Estimate totals for billing address.
|
||||
*/
|
||||
estimateTotalsBilling = function () {
|
||||
var type = quote.billingAddress().getType();
|
||||
|
||||
if (quote.isVirtual()) {
|
||||
// update totals block when estimated address was set
|
||||
totalsProcessors['default'] = totalsDefaultProvider;
|
||||
totalsProcessors[type] ?
|
||||
totalsProcessors[type].estimateTotals(quote.billingAddress()) :
|
||||
totalsProcessors['default'].estimateTotals(quote.billingAddress());
|
||||
}
|
||||
};
|
||||
|
||||
quote.shippingAddress.subscribe(estimateTotalsAndUpdateRates);
|
||||
quote.shippingMethod.subscribe(estimateTotalsShipping);
|
||||
quote.billingAddress.subscribe(estimateTotalsBilling);
|
||||
});
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'underscore',
|
||||
'Magento_Checkout/js/model/resource-url-manager',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'mage/storage',
|
||||
'Magento_Checkout/js/model/totals',
|
||||
'Magento_Checkout/js/model/error-processor',
|
||||
'Magento_Checkout/js/model/cart/cache',
|
||||
'Magento_Customer/js/customer-data'
|
||||
], function (_, resourceUrlManager, quote, storage, totalsService, errorProcessor, cartCache, customerData) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Load data from server.
|
||||
*
|
||||
* @param {Object} address
|
||||
*/
|
||||
var loadFromServer = function (address) {
|
||||
var serviceUrl,
|
||||
payload;
|
||||
|
||||
// Start loader for totals block
|
||||
totalsService.isLoading(true);
|
||||
serviceUrl = resourceUrlManager.getUrlForTotalsEstimationForNewAddress(quote);
|
||||
payload = {
|
||||
addressInformation: {
|
||||
address: _.pick(address, cartCache.requiredFields)
|
||||
}
|
||||
};
|
||||
|
||||
if (quote.shippingMethod() && quote.shippingMethod()['method_code']) {
|
||||
payload.addressInformation['shipping_method_code'] = quote.shippingMethod()['method_code'];
|
||||
payload.addressInformation['shipping_carrier_code'] = quote.shippingMethod()['carrier_code'];
|
||||
}
|
||||
|
||||
return storage.post(
|
||||
serviceUrl, JSON.stringify(payload), false
|
||||
).done(function (result) {
|
||||
var data = {
|
||||
totals: result,
|
||||
address: address,
|
||||
cartVersion: customerData.get('cart')()['data_id'],
|
||||
shippingMethodCode: null,
|
||||
shippingCarrierCode: null
|
||||
};
|
||||
|
||||
if (quote.shippingMethod() && quote.shippingMethod()['method_code']) {
|
||||
data.shippingMethodCode = quote.shippingMethod()['method_code'];
|
||||
data.shippingCarrierCode = quote.shippingMethod()['carrier_code'];
|
||||
}
|
||||
|
||||
quote.setTotals(result);
|
||||
cartCache.set('cart-data', data);
|
||||
}).fail(function (response) {
|
||||
errorProcessor.process(response);
|
||||
}).always(function () {
|
||||
// Stop loader for totals block
|
||||
totalsService.isLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
/**
|
||||
* Array of required address fields.
|
||||
* @property {Array.String} requiredFields
|
||||
* @deprecated Use cart cache.
|
||||
*/
|
||||
requiredFields: cartCache.requiredFields,
|
||||
|
||||
/**
|
||||
* Get shipping rates for specified address.
|
||||
* @param {Object} address
|
||||
*/
|
||||
estimateTotals: function (address) {
|
||||
return loadFromServer(address);
|
||||
}
|
||||
};
|
||||
});
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checkout adapter for customer data storage
|
||||
*/
|
||||
define([
|
||||
'Magento_Customer/js/model/address-list',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/checkout-data',
|
||||
'Magento_Checkout/js/action/create-shipping-address',
|
||||
'Magento_Checkout/js/action/select-shipping-address',
|
||||
'Magento_Checkout/js/action/select-shipping-method',
|
||||
'Magento_Checkout/js/model/payment-service',
|
||||
'Magento_Checkout/js/action/select-payment-method',
|
||||
'Magento_Checkout/js/model/address-converter',
|
||||
'Magento_Checkout/js/action/select-billing-address',
|
||||
'Magento_Checkout/js/action/create-billing-address',
|
||||
'underscore'
|
||||
], function (
|
||||
addressList,
|
||||
quote,
|
||||
checkoutData,
|
||||
createShippingAddress,
|
||||
selectShippingAddress,
|
||||
selectShippingMethodAction,
|
||||
paymentService,
|
||||
selectPaymentMethodAction,
|
||||
addressConverter,
|
||||
selectBillingAddress,
|
||||
createBillingAddress,
|
||||
_
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
var isBillingAddressResolvedFromBackend = false;
|
||||
|
||||
return {
|
||||
|
||||
/**
|
||||
* Resolve estimation address. Used local storage
|
||||
*/
|
||||
resolveEstimationAddress: function () {
|
||||
var address;
|
||||
|
||||
if (quote.isVirtual()) {
|
||||
if (checkoutData.getBillingAddressFromData()) {
|
||||
address = addressConverter.formAddressDataToQuoteAddress(
|
||||
checkoutData.getBillingAddressFromData()
|
||||
);
|
||||
selectBillingAddress(address);
|
||||
} else {
|
||||
this.resolveBillingAddress();
|
||||
}
|
||||
} else if (checkoutData.getShippingAddressFromData()) {
|
||||
address = addressConverter.formAddressDataToQuoteAddress(checkoutData.getShippingAddressFromData());
|
||||
selectShippingAddress(address);
|
||||
} else {
|
||||
this.resolveShippingAddress();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Resolve shipping address. Used local storage
|
||||
*/
|
||||
resolveShippingAddress: function () {
|
||||
var newCustomerShippingAddress;
|
||||
|
||||
if (!checkoutData.getShippingAddressFromData() &&
|
||||
window.checkoutConfig.shippingAddressFromData
|
||||
) {
|
||||
checkoutData.setShippingAddressFromData(window.checkoutConfig.shippingAddressFromData);
|
||||
}
|
||||
|
||||
newCustomerShippingAddress = checkoutData.getNewCustomerShippingAddress();
|
||||
|
||||
if (newCustomerShippingAddress) {
|
||||
createShippingAddress(newCustomerShippingAddress);
|
||||
}
|
||||
this.applyShippingAddress();
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply resolved estimated address to quote
|
||||
*
|
||||
* @param {Object} isEstimatedAddress
|
||||
*/
|
||||
applyShippingAddress: function (isEstimatedAddress) {
|
||||
var address,
|
||||
shippingAddress,
|
||||
isConvertAddress;
|
||||
|
||||
if (addressList().length === 0) {
|
||||
address = addressConverter.formAddressDataToQuoteAddress(
|
||||
checkoutData.getShippingAddressFromData()
|
||||
);
|
||||
selectShippingAddress(address);
|
||||
}
|
||||
shippingAddress = quote.shippingAddress();
|
||||
isConvertAddress = isEstimatedAddress || false;
|
||||
|
||||
if (!shippingAddress) {
|
||||
shippingAddress = this.getShippingAddressFromCustomerAddressList();
|
||||
|
||||
if (shippingAddress) {
|
||||
selectShippingAddress(
|
||||
isConvertAddress ?
|
||||
addressConverter.addressToEstimationAddress(shippingAddress)
|
||||
: shippingAddress
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} ratesData
|
||||
*/
|
||||
resolveShippingRates: function (ratesData) {
|
||||
var selectedShippingRate = checkoutData.getSelectedShippingRate(),
|
||||
availableRate = false;
|
||||
|
||||
if (ratesData.length === 1 && !quote.shippingMethod()) {
|
||||
//set shipping rate if we have only one available shipping rate
|
||||
selectShippingMethodAction(ratesData[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (quote.shippingMethod()) {
|
||||
availableRate = _.find(ratesData, function (rate) {
|
||||
return rate['carrier_code'] == quote.shippingMethod()['carrier_code'] && //eslint-disable-line
|
||||
rate['method_code'] == quote.shippingMethod()['method_code']; //eslint-disable-line eqeqeq
|
||||
});
|
||||
}
|
||||
|
||||
if (!availableRate && selectedShippingRate) {
|
||||
availableRate = _.find(ratesData, function (rate) {
|
||||
return rate['carrier_code'] + '_' + rate['method_code'] === selectedShippingRate;
|
||||
});
|
||||
}
|
||||
|
||||
if (!availableRate && window.checkoutConfig.selectedShippingMethod) {
|
||||
availableRate = _.find(ratesData, function (rate) {
|
||||
var selectedShippingMethod = window.checkoutConfig.selectedShippingMethod;
|
||||
|
||||
return rate['carrier_code'] == selectedShippingMethod['carrier_code'] && //eslint-disable-line
|
||||
rate['method_code'] == selectedShippingMethod['method_code']; //eslint-disable-line eqeqeq
|
||||
});
|
||||
}
|
||||
|
||||
//Unset selected shipping method if not available
|
||||
if (!availableRate) {
|
||||
selectShippingMethodAction(null);
|
||||
} else {
|
||||
selectShippingMethodAction(availableRate);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Resolve payment method. Used local storage
|
||||
*/
|
||||
resolvePaymentMethod: function () {
|
||||
var availablePaymentMethods = paymentService.getAvailablePaymentMethods(),
|
||||
selectedPaymentMethod = checkoutData.getSelectedPaymentMethod();
|
||||
|
||||
if (selectedPaymentMethod) {
|
||||
availablePaymentMethods.some(function (payment) {
|
||||
if (payment.method == selectedPaymentMethod) { //eslint-disable-line eqeqeq
|
||||
selectPaymentMethodAction(payment);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Resolve billing address. Used local storage
|
||||
*/
|
||||
resolveBillingAddress: function () {
|
||||
var selectedBillingAddress,
|
||||
newCustomerBillingAddressData;
|
||||
|
||||
selectedBillingAddress = checkoutData.getSelectedBillingAddress();
|
||||
newCustomerBillingAddressData = checkoutData.getNewCustomerBillingAddress();
|
||||
|
||||
if (selectedBillingAddress) {
|
||||
if (selectedBillingAddress === 'new-customer-billing-address' && newCustomerBillingAddressData) {
|
||||
selectBillingAddress(createBillingAddress(newCustomerBillingAddressData));
|
||||
} else {
|
||||
addressList.some(function (address) {
|
||||
if (selectedBillingAddress === address.getKey()) {
|
||||
selectBillingAddress(address);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.applyBillingAddress();
|
||||
}
|
||||
|
||||
if (!isBillingAddressResolvedFromBackend &&
|
||||
!checkoutData.getBillingAddressFromData() &&
|
||||
!_.isEmpty(window.checkoutConfig.billingAddressFromData) &&
|
||||
!quote.billingAddress()
|
||||
) {
|
||||
if (window.checkoutConfig.isBillingAddressFromDataValid === true) {
|
||||
selectBillingAddress(createBillingAddress(window.checkoutConfig.billingAddressFromData));
|
||||
} else {
|
||||
checkoutData.setBillingAddressFromData(window.checkoutConfig.billingAddressFromData);
|
||||
}
|
||||
isBillingAddressResolvedFromBackend = true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply resolved billing address to quote
|
||||
*/
|
||||
applyBillingAddress: function () {
|
||||
var shippingAddress,
|
||||
isBillingAddressInitialized;
|
||||
|
||||
if (quote.billingAddress()) {
|
||||
selectBillingAddress(quote.billingAddress());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (quote.isVirtual() || !quote.billingAddress()) {
|
||||
isBillingAddressInitialized = addressList.some(function (addrs) {
|
||||
if (addrs.isDefaultBilling()) {
|
||||
selectBillingAddress(addrs);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
shippingAddress = quote.shippingAddress();
|
||||
|
||||
if (!isBillingAddressInitialized &&
|
||||
shippingAddress &&
|
||||
shippingAddress.canUseForBilling() &&
|
||||
(shippingAddress.isDefaultShipping() || !quote.isVirtual())
|
||||
) {
|
||||
//set billing address same as shipping by default if it is not empty
|
||||
selectBillingAddress(quote.shippingAddress());
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get shipping address from address list
|
||||
*
|
||||
* @return {Object|null}
|
||||
*/
|
||||
getShippingAddressFromCustomerAddressList: function () {
|
||||
var shippingAddress = _.find(
|
||||
addressList(),
|
||||
function (address) {
|
||||
return checkoutData.getSelectedShippingAddress() == address.getKey() //eslint-disable-line
|
||||
}
|
||||
);
|
||||
|
||||
if (!shippingAddress) {
|
||||
shippingAddress = _.find(
|
||||
addressList(),
|
||||
function (address) {
|
||||
return address.isDefaultShipping();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!shippingAddress && addressList().length === 1) {
|
||||
shippingAddress = addressList()[0];
|
||||
}
|
||||
|
||||
return shippingAddress;
|
||||
}
|
||||
};
|
||||
});
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Customer/js/model/customer',
|
||||
'mage/validation'
|
||||
], function ($, customer) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
/**
|
||||
* Validate checkout agreements
|
||||
*
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function () {
|
||||
var emailValidationResult = customer.isLoggedIn(),
|
||||
loginFormSelector = 'form[data-role=email-with-possible-login]';
|
||||
|
||||
if (!customer.isLoggedIn()) {
|
||||
$(loginFormSelector).validation();
|
||||
emailValidationResult = Boolean($(loginFormSelector + ' input[name=username]').valid());
|
||||
}
|
||||
|
||||
return emailValidationResult;
|
||||
}
|
||||
};
|
||||
});
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
/**
|
||||
* @return {Object}
|
||||
*/
|
||||
getRules: function () {
|
||||
return {
|
||||
'country_id': {
|
||||
'required': true
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
});
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'mageUtils',
|
||||
'./default-validation-rules',
|
||||
'mage/translate'
|
||||
], function ($, utils, validationRules, $t) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
validationErrors: [],
|
||||
|
||||
/**
|
||||
* @param {Object} address
|
||||
* @return {Boolean}
|
||||
*/
|
||||
validate: function (address) {
|
||||
var self = this;
|
||||
|
||||
this.validationErrors = [];
|
||||
$.each(validationRules.getRules(), function (field, rule) {
|
||||
var message;
|
||||
|
||||
if (rule.required && utils.isEmpty(address[field])) {
|
||||
message = $t('Field ') + field + $t(' is required.');
|
||||
|
||||
self.validationErrors.push(message);
|
||||
}
|
||||
});
|
||||
|
||||
return !this.validationErrors.length;
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'mage/url',
|
||||
'Magento_Ui/js/model/messageList',
|
||||
'mage/translate'
|
||||
], function (url, globalMessageList, $t) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
/**
|
||||
* @param {Object} response
|
||||
* @param {Object} messageContainer
|
||||
*/
|
||||
process: function (response, messageContainer) {
|
||||
var error;
|
||||
|
||||
messageContainer = messageContainer || globalMessageList;
|
||||
|
||||
if (response.status == 401) { //eslint-disable-line eqeqeq
|
||||
this.redirectTo(url.build('customer/account/login/'));
|
||||
} else {
|
||||
try {
|
||||
error = JSON.parse(response.responseText);
|
||||
} catch (exception) {
|
||||
error = {
|
||||
message: $t('Something went wrong with your request. Please try again later.')
|
||||
};
|
||||
}
|
||||
messageContainer.addErrorMessage(error);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method to redirect by requested URL.
|
||||
*/
|
||||
redirectTo: function (redirectUrl) {
|
||||
window.location.replace(redirectUrl);
|
||||
}
|
||||
};
|
||||
});
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'rjsResolver'
|
||||
], function ($, resolver) {
|
||||
'use strict';
|
||||
|
||||
var containerId = '#checkout';
|
||||
|
||||
return {
|
||||
|
||||
/**
|
||||
* Start full page loader action
|
||||
*/
|
||||
startLoader: function () {
|
||||
$(containerId).trigger('processStart');
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop full page loader action
|
||||
*
|
||||
* @param {Boolean} [forceStop]
|
||||
*/
|
||||
stopLoader: function (forceStop) {
|
||||
var $elem = $(containerId),
|
||||
stop = $elem.trigger.bind($elem, 'processStop'); //eslint-disable-line jquery-no-bind-unbind
|
||||
|
||||
forceStop ? stop() : resolver(stop);
|
||||
}
|
||||
};
|
||||
});
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'underscore',
|
||||
'Magento_Checkout/js/model/default-post-code-resolver'
|
||||
], function (_, DefaultPostCodeResolver) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @param {Object} addressData
|
||||
* Returns new address object
|
||||
*/
|
||||
return function (addressData) {
|
||||
var identifier = Date.now(),
|
||||
countryId = addressData['country_id'] || addressData.countryId || window.checkoutConfig.defaultCountryId,
|
||||
regionId;
|
||||
|
||||
if (addressData.region && addressData.region['region_id']) {
|
||||
regionId = addressData.region['region_id'];
|
||||
} else if (!addressData['region_id']) {
|
||||
regionId = undefined;
|
||||
} else if (
|
||||
/* eslint-disable */
|
||||
addressData['country_id'] && addressData['country_id'] == window.checkoutConfig.defaultCountryId ||
|
||||
!addressData['country_id'] && countryId == window.checkoutConfig.defaultCountryId
|
||||
/* eslint-enable */
|
||||
) {
|
||||
regionId = window.checkoutConfig.defaultRegionId || undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
email: addressData.email,
|
||||
countryId: countryId,
|
||||
regionId: regionId || addressData.regionId,
|
||||
regionCode: addressData.region ? addressData.region['region_code'] : null,
|
||||
region: addressData.region ? addressData.region.region : null,
|
||||
customerId: addressData['customer_id'] || addressData.customerId,
|
||||
street: addressData.street,
|
||||
company: addressData.company,
|
||||
telephone: addressData.telephone,
|
||||
fax: addressData.fax,
|
||||
postcode: addressData.postcode ? addressData.postcode : DefaultPostCodeResolver.resolve(),
|
||||
city: addressData.city,
|
||||
firstname: addressData.firstname,
|
||||
lastname: addressData.lastname,
|
||||
middlename: addressData.middlename,
|
||||
prefix: addressData.prefix,
|
||||
suffix: addressData.suffix,
|
||||
vatId: addressData['vat_id'],
|
||||
saveInAddressBook: addressData['save_in_address_book'],
|
||||
customAttributes: addressData['custom_attributes'],
|
||||
extensionAttributes: addressData['extension_attributes'],
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
isDefaultShipping: function () {
|
||||
return addressData['default_shipping'];
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
isDefaultBilling: function () {
|
||||
return addressData['default_billing'];
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
*/
|
||||
getType: function () {
|
||||
return 'new-customer-address';
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
*/
|
||||
getKey: function () {
|
||||
return this.getType();
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
*/
|
||||
getCacheKey: function () {
|
||||
return this.getType() + identifier;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isEditable: function () {
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
canUseForBilling: function () {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
};
|
||||
});
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'underscore',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/payment/method-list',
|
||||
'Magento_Checkout/js/action/select-payment-method'
|
||||
], function (_, quote, methodList, selectPaymentMethod) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Free method filter
|
||||
* @param {Object} paymentMethod
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isFreePaymentMethod = function (paymentMethod) {
|
||||
return paymentMethod.method === 'free';
|
||||
},
|
||||
|
||||
/**
|
||||
* Grabs the grand total from quote
|
||||
* @return {Number}
|
||||
*/
|
||||
getGrandTotal = function () {
|
||||
return quote.totals()['grand_total'];
|
||||
};
|
||||
|
||||
return {
|
||||
isFreeAvailable: false,
|
||||
|
||||
/**
|
||||
* Populate the list of payment methods
|
||||
* @param {Array} methods
|
||||
*/
|
||||
setPaymentMethods: function (methods) {
|
||||
var freeMethod,
|
||||
filteredMethods,
|
||||
methodIsAvailable,
|
||||
methodNames;
|
||||
|
||||
freeMethod = _.find(methods, isFreePaymentMethod);
|
||||
this.isFreeAvailable = !!freeMethod;
|
||||
|
||||
if (freeMethod && getGrandTotal() <= 0) {
|
||||
methods.splice(0, methods.length, freeMethod);
|
||||
selectPaymentMethod(freeMethod);
|
||||
}
|
||||
|
||||
filteredMethods = _.without(methods, freeMethod);
|
||||
|
||||
if (filteredMethods.length === 1) {
|
||||
selectPaymentMethod(filteredMethods[0]);
|
||||
} else if (quote.paymentMethod()) {
|
||||
methodIsAvailable = methods.some(function (item) {
|
||||
return item.method === quote.paymentMethod().method;
|
||||
});
|
||||
//Unset selected payment method if not available
|
||||
if (!methodIsAvailable) {
|
||||
selectPaymentMethod(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite methods with existing methods to preserve ko array references.
|
||||
* This prevent ko from re-rendering those methods.
|
||||
*/
|
||||
methodNames = _.pluck(methods, 'method');
|
||||
_.map(methodList(), function (existingMethod) {
|
||||
var existingMethodIndex = methodNames.indexOf(existingMethod.method);
|
||||
|
||||
if (existingMethodIndex !== -1) {
|
||||
methods[existingMethodIndex] = existingMethod;
|
||||
}
|
||||
});
|
||||
|
||||
methodList(methods);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the list of available payment methods.
|
||||
* @return {Array}
|
||||
*/
|
||||
getAvailablePaymentMethods: function () {
|
||||
var allMethods = methodList().slice(),
|
||||
grandTotalOverZero = getGrandTotal() > 0;
|
||||
|
||||
if (!this.isFreeAvailable) {
|
||||
return allMethods;
|
||||
}
|
||||
|
||||
if (grandTotalOverZero) {
|
||||
return _.reject(allMethods, isFreePaymentMethod);
|
||||
}
|
||||
|
||||
return _.filter(allMethods, isFreePaymentMethod);
|
||||
}
|
||||
};
|
||||
});
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
var validators = [];
|
||||
|
||||
return {
|
||||
/**
|
||||
* Register unique validator
|
||||
*
|
||||
* @param {*} validator
|
||||
*/
|
||||
registerValidator: function (validator) {
|
||||
validators.push(validator);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns array of registered validators
|
||||
*
|
||||
* @returns {Array}
|
||||
*/
|
||||
getValidators: function () {
|
||||
return validators;
|
||||
},
|
||||
|
||||
/**
|
||||
* Process validators
|
||||
*
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
validate: function (hideError) {
|
||||
var validationResult = true;
|
||||
|
||||
hideError = hideError || false;
|
||||
|
||||
if (validators.length <= 0) {
|
||||
return validationResult;
|
||||
}
|
||||
|
||||
validators.forEach(function (item) {
|
||||
if (item.validate(hideError) == false) { //eslint-disable-line eqeqeq
|
||||
validationResult = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return validationResult;
|
||||
}
|
||||
};
|
||||
});
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'underscore'
|
||||
], function (_) {
|
||||
'use strict';
|
||||
|
||||
return function (methods) {
|
||||
_.each(methods, function (method) {
|
||||
if (method.hasOwnProperty('code')) {
|
||||
method.method = method.code;
|
||||
delete method.code;
|
||||
}
|
||||
});
|
||||
|
||||
return methods;
|
||||
};
|
||||
});
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'uiElement',
|
||||
'mage/translate'
|
||||
], function (Element, $t) {
|
||||
'use strict';
|
||||
|
||||
var DEFAULT_GROUP_ALIAS = 'default';
|
||||
|
||||
return Element.extend({
|
||||
defaults: {
|
||||
alias: DEFAULT_GROUP_ALIAS,
|
||||
title: $t('Payment Method'),
|
||||
sortOrder: 100,
|
||||
displayArea: 'payment-methods-items-${ $.alias }'
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if group instance is default
|
||||
*
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isDefault: function () {
|
||||
return this.alias === DEFAULT_GROUP_ALIAS;
|
||||
}
|
||||
});
|
||||
});
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'ko'
|
||||
], function (ko) {
|
||||
'use strict';
|
||||
|
||||
return ko.observableArray([]);
|
||||
});
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
requestModifiers: [],
|
||||
afterRequestListeners: []
|
||||
};
|
||||
});
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'ko'
|
||||
], function (ko) {
|
||||
'use strict';
|
||||
|
||||
return ko.observableArray([]);
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define(
|
||||
[
|
||||
'mage/storage',
|
||||
'Magento_Checkout/js/model/error-processor',
|
||||
'Magento_Checkout/js/model/full-screen-loader',
|
||||
'Magento_Customer/js/customer-data',
|
||||
'Magento_Checkout/js/model/payment/place-order-hooks',
|
||||
'underscore'
|
||||
],
|
||||
function (storage, errorProcessor, fullScreenLoader, customerData, hooks, _) {
|
||||
'use strict';
|
||||
|
||||
return function (serviceUrl, payload, messageContainer) {
|
||||
var headers = {}, redirectURL = '';
|
||||
|
||||
fullScreenLoader.startLoader();
|
||||
_.each(hooks.requestModifiers, function (modifier) {
|
||||
modifier(headers, payload);
|
||||
});
|
||||
|
||||
return storage.post(
|
||||
serviceUrl, JSON.stringify(payload), true, 'application/json', headers
|
||||
).fail(
|
||||
function (response) {
|
||||
errorProcessor.process(response, messageContainer);
|
||||
redirectURL = response.getResponseHeader('errorRedirectAction');
|
||||
|
||||
if (redirectURL) {
|
||||
setTimeout(function () {
|
||||
errorProcessor.redirectTo(redirectURL);
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
).done(
|
||||
function (response) {
|
||||
var clearData = {
|
||||
'selectedShippingAddress': null,
|
||||
'shippingAddressFromData': null,
|
||||
'newCustomerShippingAddress': null,
|
||||
'selectedShippingRate': null,
|
||||
'selectedPaymentMethod': null,
|
||||
'selectedBillingAddress': null,
|
||||
'billingAddressFromData': null,
|
||||
'newCustomerBillingAddress': null
|
||||
};
|
||||
|
||||
if (response.responseType !== 'error') {
|
||||
customerData.set('checkout-data', clearData);
|
||||
}
|
||||
}
|
||||
).always(
|
||||
function () {
|
||||
fullScreenLoader.stopLoader();
|
||||
_.each(hooks.afterRequestListeners, function (listener) {
|
||||
listener();
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'mageUtils'
|
||||
], function (utils) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
validatedPostCodeExample: [],
|
||||
|
||||
/**
|
||||
* @param {*} postCode
|
||||
* @param {*} countryId
|
||||
* @param {Array} postCodesPatterns
|
||||
* @return {Boolean}
|
||||
*/
|
||||
validate: function (postCode, countryId, postCodesPatterns) {
|
||||
var pattern, regex,
|
||||
patterns = postCodesPatterns ? postCodesPatterns[countryId] :
|
||||
window.checkoutConfig.postCodes[countryId];
|
||||
|
||||
this.validatedPostCodeExample = [];
|
||||
|
||||
if (!utils.isEmpty(postCode) && !utils.isEmpty(patterns)) {
|
||||
for (pattern in patterns) {
|
||||
if (patterns.hasOwnProperty(pattern)) { //eslint-disable-line max-depth
|
||||
this.validatedPostCodeExample.push(patterns[pattern].example);
|
||||
regex = new RegExp(patterns[pattern].pattern);
|
||||
|
||||
if (regex.test(postCode)) { //eslint-disable-line max-depth
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'ko',
|
||||
'underscore',
|
||||
'domReady!'
|
||||
], function (ko, _) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Get totals data from the extension attributes.
|
||||
* @param {*} data
|
||||
* @returns {*}
|
||||
*/
|
||||
var proceedTotalsData = function (data) {
|
||||
if (_.isObject(data) && _.isObject(data['extension_attributes'])) {
|
||||
_.each(data['extension_attributes'], function (element, index) {
|
||||
data[index] = element;
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
billingAddress = ko.observable(null),
|
||||
shippingAddress = ko.observable(null),
|
||||
shippingMethod = ko.observable(null),
|
||||
paymentMethod = ko.observable(null),
|
||||
quoteData = window.checkoutConfig.quoteData,
|
||||
basePriceFormat = window.checkoutConfig.basePriceFormat,
|
||||
priceFormat = window.checkoutConfig.priceFormat,
|
||||
storeCode = window.checkoutConfig.storeCode,
|
||||
totalsData = proceedTotalsData(window.checkoutConfig.totalsData),
|
||||
totals = ko.observable(totalsData),
|
||||
collectedTotals = ko.observable({});
|
||||
|
||||
return {
|
||||
totals: totals,
|
||||
shippingAddress: shippingAddress,
|
||||
shippingMethod: shippingMethod,
|
||||
billingAddress: billingAddress,
|
||||
paymentMethod: paymentMethod,
|
||||
quoteData: quoteData,
|
||||
guestEmail: null,
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getQuoteId: function () {
|
||||
return quoteData['entity_id'];
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isVirtual: function () {
|
||||
return !!Number(quoteData['is_virtual']);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getPriceFormat: function () {
|
||||
return priceFormat;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getBasePriceFormat: function () {
|
||||
return basePriceFormat;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getItems: function () {
|
||||
return window.checkoutConfig.quoteItemData;
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getTotals: function () {
|
||||
return totals;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} data
|
||||
*/
|
||||
setTotals: function (data) {
|
||||
data = proceedTotalsData(data);
|
||||
totals(data);
|
||||
this.setCollectedTotals('subtotal_with_discount', parseFloat(data['subtotal_with_discount']));
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {*} paymentMethodCode
|
||||
*/
|
||||
setPaymentMethod: function (paymentMethodCode) {
|
||||
paymentMethod(paymentMethodCode);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getPaymentMethod: function () {
|
||||
return paymentMethod;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getStoreCode: function () {
|
||||
return storeCode;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} code
|
||||
* @param {*} value
|
||||
*/
|
||||
setCollectedTotals: function (code, value) {
|
||||
var colTotals = collectedTotals();
|
||||
|
||||
colTotals[code] = value;
|
||||
collectedTotals(colTotals);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Number}
|
||||
*/
|
||||
getCalculatedTotal: function () {
|
||||
var total = 0.; //eslint-disable-line no-floating-decimal
|
||||
|
||||
_.each(collectedTotals(), function (value) {
|
||||
total += value;
|
||||
});
|
||||
|
||||
return total;
|
||||
}
|
||||
};
|
||||
});
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'Magento_Customer/js/model/customer',
|
||||
'Magento_Checkout/js/model/url-builder',
|
||||
'mageUtils'
|
||||
], function (customer, urlBuilder, utils) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
/**
|
||||
* @param {Object} quote
|
||||
* @return {*}
|
||||
*/
|
||||
getUrlForTotalsEstimationForNewAddress: function (quote) {
|
||||
var params = this.getCheckoutMethod() == 'guest' ? //eslint-disable-line eqeqeq
|
||||
{
|
||||
cartId: quote.getQuoteId()
|
||||
} : {},
|
||||
urls = {
|
||||
'guest': '/guest-carts/:cartId/totals-information',
|
||||
'customer': '/carts/mine/totals-information'
|
||||
};
|
||||
|
||||
return this.getUrl(urls, params);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} quote
|
||||
* @return {*}
|
||||
*/
|
||||
getUrlForEstimationShippingMethodsForNewAddress: function (quote) {
|
||||
var params = this.getCheckoutMethod() == 'guest' ? //eslint-disable-line eqeqeq
|
||||
{
|
||||
quoteId: quote.getQuoteId()
|
||||
} : {},
|
||||
urls = {
|
||||
'guest': '/guest-carts/:quoteId/estimate-shipping-methods',
|
||||
'customer': '/carts/mine/estimate-shipping-methods'
|
||||
};
|
||||
|
||||
return this.getUrl(urls, params);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} quote
|
||||
* @return {*}
|
||||
*/
|
||||
getUrlForEstimationShippingMethodsByAddressId: function (quote) {
|
||||
var params = this.getCheckoutMethod() == 'guest' ? //eslint-disable-line eqeqeq
|
||||
{
|
||||
quoteId: quote.getQuoteId()
|
||||
} : {},
|
||||
urls = {
|
||||
'default': '/carts/mine/estimate-shipping-methods-by-address-id'
|
||||
};
|
||||
|
||||
return this.getUrl(urls, params);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} couponCode
|
||||
* @param {String} quoteId
|
||||
* @return {*}
|
||||
*/
|
||||
getApplyCouponUrl: function (couponCode, quoteId) {
|
||||
var params = this.getCheckoutMethod() == 'guest' ? //eslint-disable-line eqeqeq
|
||||
{
|
||||
quoteId: quoteId
|
||||
} : {},
|
||||
urls = {
|
||||
'guest': '/guest-carts/' + quoteId + '/coupons/' + encodeURIComponent(couponCode),
|
||||
'customer': '/carts/mine/coupons/' + encodeURIComponent(couponCode)
|
||||
};
|
||||
|
||||
return this.getUrl(urls, params);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} quoteId
|
||||
* @return {*}
|
||||
*/
|
||||
getCancelCouponUrl: function (quoteId) {
|
||||
var params = this.getCheckoutMethod() == 'guest' ? //eslint-disable-line eqeqeq
|
||||
{
|
||||
quoteId: quoteId
|
||||
} : {},
|
||||
urls = {
|
||||
'guest': '/guest-carts/' + quoteId + '/coupons/',
|
||||
'customer': '/carts/mine/coupons/'
|
||||
};
|
||||
|
||||
return this.getUrl(urls, params);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} quote
|
||||
* @return {*}
|
||||
*/
|
||||
getUrlForCartTotals: function (quote) {
|
||||
var params = this.getCheckoutMethod() == 'guest' ? //eslint-disable-line eqeqeq
|
||||
{
|
||||
quoteId: quote.getQuoteId()
|
||||
} : {},
|
||||
urls = {
|
||||
'guest': '/guest-carts/:quoteId/totals',
|
||||
'customer': '/carts/mine/totals'
|
||||
};
|
||||
|
||||
return this.getUrl(urls, params);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} quote
|
||||
* @return {*}
|
||||
*/
|
||||
getUrlForSetShippingInformation: function (quote) {
|
||||
var params = this.getCheckoutMethod() == 'guest' ? //eslint-disable-line eqeqeq
|
||||
{
|
||||
cartId: quote.getQuoteId()
|
||||
} : {},
|
||||
urls = {
|
||||
'guest': '/guest-carts/:cartId/shipping-information',
|
||||
'customer': '/carts/mine/shipping-information'
|
||||
};
|
||||
|
||||
return this.getUrl(urls, params);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get url for service.
|
||||
*
|
||||
* @param {*} urls
|
||||
* @param {*} urlParams
|
||||
* @return {String|*}
|
||||
*/
|
||||
getUrl: function (urls, urlParams) {
|
||||
var url;
|
||||
|
||||
if (utils.isEmpty(urls)) {
|
||||
return 'Provided service call does not exist.';
|
||||
}
|
||||
|
||||
if (!utils.isEmpty(urls['default'])) {
|
||||
url = urls['default'];
|
||||
} else {
|
||||
url = urls[this.getCheckoutMethod()];
|
||||
}
|
||||
|
||||
return urlBuilder.createUrl(url, urlParams);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
*/
|
||||
getCheckoutMethod: function () {
|
||||
return customer.isLoggedIn() ? 'customer' : 'guest';
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'ko'
|
||||
], function (ko) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
isVisible: ko.observable(false)
|
||||
};
|
||||
});
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'Magento_Checkout/js/model/resource-url-manager',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'mage/storage',
|
||||
'Magento_Checkout/js/model/shipping-service',
|
||||
'Magento_Checkout/js/model/shipping-rate-registry',
|
||||
'Magento_Checkout/js/model/error-processor'
|
||||
], function (resourceUrlManager, quote, storage, shippingService, rateRegistry, errorProcessor) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
/**
|
||||
* @param {Object} address
|
||||
*/
|
||||
getRates: function (address) {
|
||||
var cache;
|
||||
|
||||
shippingService.isLoading(true);
|
||||
cache = rateRegistry.get(address.getKey());
|
||||
|
||||
if (cache) {
|
||||
shippingService.setShippingRates(cache);
|
||||
shippingService.isLoading(false);
|
||||
} else {
|
||||
storage.post(
|
||||
resourceUrlManager.getUrlForEstimationShippingMethodsByAddressId(),
|
||||
JSON.stringify({
|
||||
addressId: address.customerAddressId
|
||||
}),
|
||||
false
|
||||
).done(function (result) {
|
||||
rateRegistry.set(address.getKey(), result);
|
||||
shippingService.setShippingRates(result);
|
||||
}).fail(function (response) {
|
||||
shippingService.setShippingRates([]);
|
||||
errorProcessor.process(response);
|
||||
}).always(function () {
|
||||
shippingService.isLoading(false);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
define([
|
||||
'Magento_Checkout/js/model/resource-url-manager',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'mage/storage',
|
||||
'Magento_Checkout/js/model/shipping-service',
|
||||
'Magento_Checkout/js/model/shipping-rate-registry',
|
||||
'Magento_Checkout/js/model/error-processor'
|
||||
], function (resourceUrlManager, quote, storage, shippingService, rateRegistry, errorProcessor) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
/**
|
||||
* Get shipping rates for specified address.
|
||||
* @param {Object} address
|
||||
*/
|
||||
getRates: function (address) {
|
||||
var cache, serviceUrl, payload;
|
||||
|
||||
shippingService.isLoading(true);
|
||||
cache = rateRegistry.get(address.getCacheKey());
|
||||
serviceUrl = resourceUrlManager.getUrlForEstimationShippingMethodsForNewAddress(quote);
|
||||
payload = JSON.stringify({
|
||||
address: {
|
||||
'street': address.street,
|
||||
'city': address.city,
|
||||
'region_id': address.regionId,
|
||||
'region': address.region,
|
||||
'country_id': address.countryId,
|
||||
'postcode': address.postcode,
|
||||
'email': address.email,
|
||||
'customer_id': address.customerId,
|
||||
'firstname': address.firstname,
|
||||
'lastname': address.lastname,
|
||||
'middlename': address.middlename,
|
||||
'prefix': address.prefix,
|
||||
'suffix': address.suffix,
|
||||
'vat_id': address.vatId,
|
||||
'company': address.company,
|
||||
'telephone': address.telephone,
|
||||
'fax': address.fax,
|
||||
'custom_attributes': address.customAttributes,
|
||||
'save_in_address_book': address.saveInAddressBook
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (cache) {
|
||||
shippingService.setShippingRates(cache);
|
||||
shippingService.isLoading(false);
|
||||
} else {
|
||||
storage.post(
|
||||
serviceUrl, payload, false
|
||||
).done(function (result) {
|
||||
rateRegistry.set(address.getCacheKey(), result);
|
||||
shippingService.setShippingRates(result);
|
||||
}).fail(function (response) {
|
||||
shippingService.setShippingRates([]);
|
||||
errorProcessor.process(response);
|
||||
}).always(function () {
|
||||
shippingService.isLoading(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
var cache = [];
|
||||
|
||||
return {
|
||||
/**
|
||||
* @param {String} addressKey
|
||||
* @return {*}
|
||||
*/
|
||||
get: function (addressKey) {
|
||||
if (cache[addressKey]) {
|
||||
return cache[addressKey];
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} addressKey
|
||||
* @param {*} data
|
||||
*/
|
||||
set: function (addressKey, data) {
|
||||
cache[addressKey] = data;
|
||||
}
|
||||
};
|
||||
});
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/shipping-rate-processor/new-address',
|
||||
'Magento_Checkout/js/model/shipping-rate-processor/customer-address'
|
||||
], function (quote, defaultProcessor, customerAddressProcessor) {
|
||||
'use strict';
|
||||
|
||||
var processors = {};
|
||||
|
||||
processors.default = defaultProcessor;
|
||||
processors['customer-address'] = customerAddressProcessor;
|
||||
|
||||
quote.shippingAddress.subscribe(function () {
|
||||
var type = quote.shippingAddress().getType();
|
||||
|
||||
if (processors[type]) {
|
||||
processors[type].getRates(quote.shippingAddress());
|
||||
} else {
|
||||
processors.default.getRates(quote.shippingAddress());
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
/**
|
||||
* @param {String} type
|
||||
* @param {*} processor
|
||||
*/
|
||||
registerProcessor: function (type, processor) {
|
||||
processors[type] = processor;
|
||||
}
|
||||
};
|
||||
});
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define(['jquery'], function ($) {
|
||||
'use strict';
|
||||
|
||||
var ratesRules = {},
|
||||
checkoutConfig = window.checkoutConfig;
|
||||
|
||||
return {
|
||||
/**
|
||||
* @param {String} carrier
|
||||
* @param {Object} rules
|
||||
*/
|
||||
registerRules: function (carrier, rules) {
|
||||
if (checkoutConfig.activeCarriers.indexOf(carrier) !== -1) {
|
||||
ratesRules[carrier] = rules.getRules();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Object}
|
||||
*/
|
||||
getRules: function () {
|
||||
return ratesRules;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Array}
|
||||
*/
|
||||
getObservableFields: function () {
|
||||
var self = this,
|
||||
observableFields = [];
|
||||
|
||||
$.each(self.getRules(), function (carrier, fields) {
|
||||
$.each(fields, function (field) {
|
||||
if (observableFields.indexOf(field) === -1) {
|
||||
observableFields.push(field);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return observableFields;
|
||||
}
|
||||
};
|
||||
});
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'ko',
|
||||
'./shipping-rates-validation-rules',
|
||||
'../model/address-converter',
|
||||
'../action/select-shipping-address',
|
||||
'./postcode-validator',
|
||||
'./default-validator',
|
||||
'mage/translate',
|
||||
'uiRegistry',
|
||||
'Magento_Checkout/js/model/shipping-address/form-popup-state',
|
||||
'Magento_Checkout/js/model/quote'
|
||||
], function (
|
||||
$,
|
||||
ko,
|
||||
shippingRatesValidationRules,
|
||||
addressConverter,
|
||||
selectShippingAddress,
|
||||
postcodeValidator,
|
||||
defaultValidator,
|
||||
$t,
|
||||
uiRegistry,
|
||||
formPopUpState
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
var checkoutConfig = window.checkoutConfig,
|
||||
validators = [],
|
||||
observedElements = [],
|
||||
postcodeElements = [],
|
||||
postcodeElementName = 'postcode';
|
||||
|
||||
validators.push(defaultValidator);
|
||||
|
||||
return {
|
||||
validateAddressTimeout: 0,
|
||||
validateZipCodeTimeout: 0,
|
||||
validateDelay: 2000,
|
||||
|
||||
/**
|
||||
* @param {String} carrier
|
||||
* @param {Object} validator
|
||||
*/
|
||||
registerValidator: function (carrier, validator) {
|
||||
if (checkoutConfig.activeCarriers.indexOf(carrier) !== -1) {
|
||||
validators.push(validator);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} address
|
||||
* @return {Boolean}
|
||||
*/
|
||||
validateAddressData: function (address) {
|
||||
return validators.some(function (validator) {
|
||||
return validator.validate(address);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Perform postponed binding for fieldset elements
|
||||
*
|
||||
* @param {String} formPath
|
||||
*/
|
||||
initFields: function (formPath) {
|
||||
var self = this,
|
||||
elements = shippingRatesValidationRules.getObservableFields();
|
||||
|
||||
if ($.inArray(postcodeElementName, elements) === -1) {
|
||||
// Add postcode field to observables if not exist for zip code validation support
|
||||
elements.push(postcodeElementName);
|
||||
}
|
||||
|
||||
$.each(elements, function (index, field) {
|
||||
uiRegistry.async(formPath + '.' + field)(self.doElementBinding.bind(self));
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Bind shipping rates request to form element
|
||||
*
|
||||
* @param {Object} element
|
||||
* @param {Boolean} force
|
||||
* @param {Number} delay
|
||||
*/
|
||||
doElementBinding: function (element, force, delay) {
|
||||
var observableFields = shippingRatesValidationRules.getObservableFields();
|
||||
|
||||
if (element && (observableFields.indexOf(element.index) !== -1 || force)) {
|
||||
if (element.index !== postcodeElementName) {
|
||||
this.bindHandler(element, delay);
|
||||
}
|
||||
}
|
||||
|
||||
if (element.index === postcodeElementName) {
|
||||
this.bindHandler(element, delay);
|
||||
postcodeElements.push(element);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {*} elements
|
||||
* @param {Boolean} force
|
||||
* @param {Number} delay
|
||||
*/
|
||||
bindChangeHandlers: function (elements, force, delay) {
|
||||
var self = this;
|
||||
|
||||
$.each(elements, function (index, elem) {
|
||||
self.doElementBinding(elem, force, delay);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} element
|
||||
* @param {Number} delay
|
||||
*/
|
||||
bindHandler: function (element, delay) {
|
||||
var self = this;
|
||||
|
||||
delay = typeof delay === 'undefined' ? self.validateDelay : delay;
|
||||
|
||||
if (element.component.indexOf('/group') !== -1) {
|
||||
$.each(element.elems(), function (index, elem) {
|
||||
self.bindHandler(elem);
|
||||
});
|
||||
} else {
|
||||
element.on('value', function () {
|
||||
clearTimeout(self.validateZipCodeTimeout);
|
||||
self.validateZipCodeTimeout = setTimeout(function () {
|
||||
if (element.index === postcodeElementName) {
|
||||
self.postcodeValidation(element);
|
||||
} else {
|
||||
$.each(postcodeElements, function (index, elem) {
|
||||
self.postcodeValidation(elem);
|
||||
});
|
||||
}
|
||||
}, delay);
|
||||
|
||||
if (!formPopUpState.isVisible()) {
|
||||
clearTimeout(self.validateAddressTimeout);
|
||||
self.validateAddressTimeout = setTimeout(function () {
|
||||
self.validateFields();
|
||||
}, delay);
|
||||
}
|
||||
});
|
||||
observedElements.push(element);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
postcodeValidation: function (postcodeElement) {
|
||||
var countryId = $('select[name="country_id"]:visible').val(),
|
||||
validationResult,
|
||||
warnMessage;
|
||||
|
||||
if (postcodeElement == null || postcodeElement.value() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
postcodeElement.warn(null);
|
||||
validationResult = postcodeValidator.validate(postcodeElement.value(), countryId);
|
||||
|
||||
if (!validationResult) {
|
||||
warnMessage = $t('Provided Zip/Postal Code seems to be invalid.');
|
||||
|
||||
if (postcodeValidator.validatedPostCodeExample.length) {
|
||||
warnMessage += $t(' Example: ') + postcodeValidator.validatedPostCodeExample.join('; ') + '. ';
|
||||
}
|
||||
warnMessage += $t('If you believe it is the right one you can ignore this notice.');
|
||||
postcodeElement.warn(warnMessage);
|
||||
}
|
||||
|
||||
return validationResult;
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert form data to quote address and validate fields for shipping rates
|
||||
*/
|
||||
validateFields: function () {
|
||||
var addressFlat = addressConverter.formDataProviderToFlatData(
|
||||
this.collectObservedData(),
|
||||
'shippingAddress'
|
||||
),
|
||||
address;
|
||||
|
||||
if (this.validateAddressData(addressFlat)) {
|
||||
addressFlat = uiRegistry.get('checkoutProvider').shippingAddress;
|
||||
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
|
||||
selectShippingAddress(address);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Collect observed fields data to object
|
||||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
collectObservedData: function () {
|
||||
var observedValues = {};
|
||||
|
||||
$.each(observedElements, function (index, field) {
|
||||
observedValues[field.dataScope] = field.value();
|
||||
});
|
||||
|
||||
return observedValues;
|
||||
}
|
||||
};
|
||||
});
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'Magento_Checkout/js/model/shipping-save-processor/default'
|
||||
], function (defaultProcessor) {
|
||||
'use strict';
|
||||
|
||||
var processors = {};
|
||||
|
||||
processors['default'] = defaultProcessor;
|
||||
|
||||
return {
|
||||
/**
|
||||
* @param {String} type
|
||||
* @param {*} processor
|
||||
*/
|
||||
registerProcessor: function (type, processor) {
|
||||
processors[type] = processor;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} type
|
||||
* @return {Array}
|
||||
*/
|
||||
saveShippingInformation: function (type) {
|
||||
var rates = [];
|
||||
|
||||
if (processors[type]) {
|
||||
rates = processors[type].saveShippingInformation();
|
||||
} else {
|
||||
rates = processors['default'].saveShippingInformation();
|
||||
}
|
||||
|
||||
return rates;
|
||||
}
|
||||
};
|
||||
});
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'ko',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/resource-url-manager',
|
||||
'mage/storage',
|
||||
'Magento_Checkout/js/model/payment-service',
|
||||
'Magento_Checkout/js/model/payment/method-converter',
|
||||
'Magento_Checkout/js/model/error-processor',
|
||||
'Magento_Checkout/js/model/full-screen-loader',
|
||||
'Magento_Checkout/js/action/select-billing-address',
|
||||
'Magento_Checkout/js/model/shipping-save-processor/payload-extender'
|
||||
], function (
|
||||
ko,
|
||||
quote,
|
||||
resourceUrlManager,
|
||||
storage,
|
||||
paymentService,
|
||||
methodConverter,
|
||||
errorProcessor,
|
||||
fullScreenLoader,
|
||||
selectBillingAddressAction,
|
||||
payloadExtender
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
/**
|
||||
* @return {jQuery.Deferred}
|
||||
*/
|
||||
saveShippingInformation: function () {
|
||||
var payload;
|
||||
|
||||
if (!quote.billingAddress() && quote.shippingAddress().canUseForBilling()) {
|
||||
selectBillingAddressAction(quote.shippingAddress());
|
||||
}
|
||||
|
||||
payload = {
|
||||
addressInformation: {
|
||||
'shipping_address': quote.shippingAddress(),
|
||||
'billing_address': quote.billingAddress(),
|
||||
'shipping_method_code': quote.shippingMethod()['method_code'],
|
||||
'shipping_carrier_code': quote.shippingMethod()['carrier_code']
|
||||
}
|
||||
};
|
||||
|
||||
payloadExtender(payload);
|
||||
|
||||
fullScreenLoader.startLoader();
|
||||
|
||||
return storage.post(
|
||||
resourceUrlManager.getUrlForSetShippingInformation(quote),
|
||||
JSON.stringify(payload)
|
||||
).done(
|
||||
function (response) {
|
||||
quote.setTotals(response.totals);
|
||||
paymentService.setPaymentMethods(methodConverter(response['payment_methods']));
|
||||
fullScreenLoader.stopLoader();
|
||||
}
|
||||
).fail(
|
||||
function (response) {
|
||||
errorProcessor.process(response);
|
||||
fullScreenLoader.stopLoader();
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
});
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
return function (payload) {
|
||||
payload.addressInformation['extension_attributes'] = {};
|
||||
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'ko',
|
||||
'Magento_Checkout/js/model/checkout-data-resolver'
|
||||
], function (ko, checkoutDataResolver) {
|
||||
'use strict';
|
||||
|
||||
var shippingRates = ko.observableArray([]);
|
||||
|
||||
return {
|
||||
isLoading: ko.observable(false),
|
||||
|
||||
/**
|
||||
* Set shipping rates
|
||||
*
|
||||
* @param {*} ratesData
|
||||
*/
|
||||
setShippingRates: function (ratesData) {
|
||||
shippingRates(ratesData);
|
||||
shippingRates.valueHasMutated();
|
||||
checkoutDataResolver.resolveShippingRates(ratesData);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get shipping rates
|
||||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
getShippingRates: function () {
|
||||
return shippingRates;
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
popUp: false,
|
||||
|
||||
/**
|
||||
* @param {Object} popUp
|
||||
*/
|
||||
setPopup: function (popUp) {
|
||||
this.popUp = popUp;
|
||||
},
|
||||
|
||||
/**
|
||||
* Show popup.
|
||||
*/
|
||||
show: function () {
|
||||
if (this.popUp) {
|
||||
this.popUp.modal('openModal');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Hide popup.
|
||||
*/
|
||||
hide: function () {
|
||||
if (this.popUp) {
|
||||
this.popUp.modal('closeModal');
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,216 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'ko'
|
||||
], function ($, ko) {
|
||||
'use strict';
|
||||
|
||||
var steps = ko.observableArray();
|
||||
|
||||
return {
|
||||
steps: steps,
|
||||
stepCodes: [],
|
||||
validCodes: [],
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
handleHash: function () {
|
||||
var hashString = window.location.hash.replace('#', ''),
|
||||
isRequestedStepVisible;
|
||||
|
||||
if (hashString === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($.inArray(hashString, this.validCodes) === -1) {
|
||||
window.location.href = window.checkoutConfig.pageNotFoundUrl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
isRequestedStepVisible = steps.sort(this.sortItems).some(function (element) {
|
||||
return (element.code == hashString || element.alias == hashString) && element.isVisible(); //eslint-disable-line
|
||||
});
|
||||
|
||||
//if requested step is visible, then we don't need to load step data from server
|
||||
if (isRequestedStepVisible) {
|
||||
return false;
|
||||
}
|
||||
|
||||
steps().sort(this.sortItems).forEach(function (element) {
|
||||
if (element.code == hashString || element.alias == hashString) { //eslint-disable-line eqeqeq
|
||||
element.navigate(element);
|
||||
} else {
|
||||
element.isVisible(false);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} code
|
||||
* @param {*} alias
|
||||
* @param {*} title
|
||||
* @param {Function} isVisible
|
||||
* @param {*} navigate
|
||||
* @param {*} sortOrder
|
||||
*/
|
||||
registerStep: function (code, alias, title, isVisible, navigate, sortOrder) {
|
||||
var hash, active;
|
||||
|
||||
if ($.inArray(code, this.validCodes) !== -1) {
|
||||
throw new DOMException('Step code [' + code + '] already registered in step navigator');
|
||||
}
|
||||
|
||||
if (alias != null) {
|
||||
if ($.inArray(alias, this.validCodes) !== -1) {
|
||||
throw new DOMException('Step code [' + alias + '] already registered in step navigator');
|
||||
}
|
||||
this.validCodes.push(alias);
|
||||
}
|
||||
this.validCodes.push(code);
|
||||
steps.push({
|
||||
code: code,
|
||||
alias: alias != null ? alias : code,
|
||||
title: title,
|
||||
isVisible: isVisible,
|
||||
navigate: navigate,
|
||||
sortOrder: sortOrder
|
||||
});
|
||||
active = this.getActiveItemIndex();
|
||||
steps.each(function (elem, index) {
|
||||
if (active !== index) {
|
||||
elem.isVisible(false);
|
||||
}
|
||||
});
|
||||
this.stepCodes.push(code);
|
||||
hash = window.location.hash.replace('#', '');
|
||||
|
||||
if (hash != '' && hash != code) { //eslint-disable-line eqeqeq
|
||||
//Force hiding of not active step
|
||||
isVisible(false);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} itemOne
|
||||
* @param {Object} itemTwo
|
||||
* @return {Number}
|
||||
*/
|
||||
sortItems: function (itemOne, itemTwo) {
|
||||
return itemOne.sortOrder > itemTwo.sortOrder ? 1 : -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Number}
|
||||
*/
|
||||
getActiveItemIndex: function () {
|
||||
var activeIndex = 0;
|
||||
|
||||
steps().sort(this.sortItems).some(function (element, index) {
|
||||
if (element.isVisible()) {
|
||||
activeIndex = index;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
return activeIndex;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {*} code
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isProcessed: function (code) {
|
||||
var activeItemIndex = this.getActiveItemIndex(),
|
||||
sortedItems = steps().sort(this.sortItems),
|
||||
requestedItemIndex = -1;
|
||||
|
||||
sortedItems.forEach(function (element, index) {
|
||||
if (element.code == code) { //eslint-disable-line eqeqeq
|
||||
requestedItemIndex = index;
|
||||
}
|
||||
});
|
||||
|
||||
return activeItemIndex > requestedItemIndex;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {*} code
|
||||
* @param {*} scrollToElementId
|
||||
*/
|
||||
navigateTo: function (code, scrollToElementId) {
|
||||
var sortedItems = steps().sort(this.sortItems),
|
||||
bodyElem = $('body');
|
||||
|
||||
scrollToElementId = scrollToElementId || null;
|
||||
|
||||
if (!this.isProcessed(code)) {
|
||||
return;
|
||||
}
|
||||
sortedItems.forEach(function (element) {
|
||||
if (element.code == code) { //eslint-disable-line eqeqeq
|
||||
element.isVisible(true);
|
||||
bodyElem.animate({
|
||||
scrollTop: $('#' + code).offset().top
|
||||
}, 0, function () {
|
||||
window.location = window.checkoutConfig.checkoutUrl + '#' + code;
|
||||
});
|
||||
|
||||
if (scrollToElementId && $('#' + scrollToElementId).length) {
|
||||
bodyElem.animate({
|
||||
scrollTop: $('#' + scrollToElementId).offset().top
|
||||
}, 0);
|
||||
}
|
||||
} else {
|
||||
element.isVisible(false);
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets window location hash.
|
||||
*
|
||||
* @param {String} hash
|
||||
*/
|
||||
setHash: function (hash) {
|
||||
window.location.hash = hash;
|
||||
},
|
||||
|
||||
/**
|
||||
* Next step.
|
||||
*/
|
||||
next: function () {
|
||||
var activeIndex = 0,
|
||||
code;
|
||||
|
||||
steps().sort(this.sortItems).forEach(function (element, index) {
|
||||
if (element.isVisible()) {
|
||||
element.isVisible(false);
|
||||
activeIndex = index;
|
||||
}
|
||||
});
|
||||
|
||||
if (steps().length > activeIndex + 1) {
|
||||
code = steps()[activeIndex + 1].code;
|
||||
steps()[activeIndex + 1].isVisible(true);
|
||||
this.setHash(code);
|
||||
document.body.scrollTop = document.documentElement.scrollTop = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
define([
|
||||
'ko',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Customer/js/customer-data'
|
||||
], function (ko, quote, customerData) {
|
||||
'use strict';
|
||||
|
||||
var quoteItems = ko.observable(quote.totals().items),
|
||||
cartData = customerData.get('cart'),
|
||||
quoteSubtotal = parseFloat(quote.totals().subtotal),
|
||||
subtotalAmount = parseFloat(cartData().subtotalAmount);
|
||||
|
||||
quote.totals.subscribe(function (newValue) {
|
||||
quoteItems(newValue.items);
|
||||
});
|
||||
|
||||
if (!isNaN(subtotalAmount) && quoteSubtotal !== subtotalAmount && quoteSubtotal !== 0) {
|
||||
customerData.reload(['cart'], false);
|
||||
}
|
||||
|
||||
return {
|
||||
totals: quote.totals,
|
||||
isLoading: ko.observable(false),
|
||||
|
||||
/**
|
||||
* @return {Function}
|
||||
*/
|
||||
getItems: function () {
|
||||
return quoteItems;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {*} code
|
||||
* @return {*}
|
||||
*/
|
||||
getSegment: function (code) {
|
||||
var i, total;
|
||||
|
||||
if (!this.totals()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (i in this.totals()['total_segments']) { //eslint-disable-line guard-for-in
|
||||
total = this.totals()['total_segments'][i];
|
||||
|
||||
if (total.code == code) { //eslint-disable-line eqeqeq
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define(['jquery'], function ($) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
method: 'rest',
|
||||
storeCode: window.checkoutConfig.storeCode,
|
||||
version: 'V1',
|
||||
serviceUrl: ':method/:storeCode/:version',
|
||||
|
||||
/**
|
||||
* @param {String} url
|
||||
* @param {Object} params
|
||||
* @return {*}
|
||||
*/
|
||||
createUrl: function (url, params) {
|
||||
var completeUrl = this.serviceUrl + url;
|
||||
|
||||
return this.bindParams(completeUrl, params);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} url
|
||||
* @param {Object} params
|
||||
* @return {*}
|
||||
*/
|
||||
bindParams: function (url, params) {
|
||||
var urlParts;
|
||||
|
||||
params.method = this.method;
|
||||
params.storeCode = this.storeCode;
|
||||
params.version = this.version;
|
||||
|
||||
urlParts = url.split('/');
|
||||
urlParts = urlParts.filter(Boolean);
|
||||
|
||||
$.each(urlParts, function (key, part) {
|
||||
part = part.replace(':', '');
|
||||
|
||||
if (params[part] != undefined) { //eslint-disable-line eqeqeq
|
||||
urlParts[key] = params[part];
|
||||
}
|
||||
});
|
||||
|
||||
return urlParts.join('/');
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Customer/js/model/authentication-popup',
|
||||
'Magento_Customer/js/customer-data'
|
||||
], function ($, authenticationPopup, customerData) {
|
||||
'use strict';
|
||||
|
||||
return function (config, element) {
|
||||
$(element).on('click', function (event) {
|
||||
var cart = customerData.get('cart'),
|
||||
customer = customerData.get('customer');
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
|
||||
authenticationPopup.showModal();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 下单校验销售必须已经选择
|
||||
if(!$('select.xiaos_list').val()){
|
||||
$('select.xiaos_list').addClass('has-error');
|
||||
$('.sale-error-tip').show();
|
||||
$('html, body').animate({
|
||||
scrollTop: 120
|
||||
}, 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
let flag = true
|
||||
$('.cart.table-wrapper .cart.item').each(function(){
|
||||
const accountInput = $(this).children().find('.yi_list').val();
|
||||
if(!accountInput){
|
||||
$(this).addClass('has-error');
|
||||
$(this).children().find('.field-error-tip').show();
|
||||
flag = false
|
||||
} else {
|
||||
$(this).removeClass('has-error');
|
||||
$(this).children().find('.field-error-tip').hide();
|
||||
}
|
||||
});
|
||||
if(!flag){
|
||||
const errorTipTop = $('.cart.table-wrapper .cart.item.has-error').offset().top + 200;
|
||||
$('html, body').animate({
|
||||
scrollTop: errorTipTop
|
||||
}, 500);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 设置后绑定触发更新购物车按钮提交购物车表单
|
||||
$('.form.form-cart button.update').trigger('click');
|
||||
$(element).attr('disabled', true);
|
||||
|
||||
// 设置购物车表单内隐藏字段goCheckout为1表示跳转到结算,默认0是更新购物车不跳转
|
||||
$('#go_checkout_url').val(1);
|
||||
//location.href = config.checkoutUrl;
|
||||
});
|
||||
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,263 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'mage/template',
|
||||
'underscore',
|
||||
'jquery-ui-modules/widget',
|
||||
'mage/validation'
|
||||
], function ($, mageTemplate, _) {
|
||||
'use strict';
|
||||
|
||||
$.widget('mage.regionUpdater', {
|
||||
options: {
|
||||
regionTemplate:
|
||||
'<option value="<%- data.value %>" <% if (data.isSelected) { %>selected="selected"<% } %>>' +
|
||||
'<%- data.title %>' +
|
||||
'</option>',
|
||||
isRegionRequired: true,
|
||||
isZipRequired: true,
|
||||
isCountryRequired: true,
|
||||
currentRegion: null,
|
||||
isMultipleCountriesAllowed: true
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_create: function () {
|
||||
this._initCountryElement();
|
||||
|
||||
this.currentRegionOption = this.options.currentRegion;
|
||||
this.regionTmpl = mageTemplate(this.options.regionTemplate);
|
||||
|
||||
this._updateRegion(this.element.find('option:selected').val());
|
||||
|
||||
$(this.options.regionListId).on('change', $.proxy(function (e) {
|
||||
this.setOption = false;
|
||||
this.currentRegionOption = $(e.target).val();
|
||||
}, this));
|
||||
|
||||
$(this.options.regionInputId).on('focusout', $.proxy(function () {
|
||||
this.setOption = true;
|
||||
}, this));
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_initCountryElement: function () {
|
||||
|
||||
if (this.options.isMultipleCountriesAllowed) {
|
||||
this.element.parents('div.field').show();
|
||||
this.element.on('change', $.proxy(function (e) {
|
||||
// clear region inputs on country change
|
||||
$(this.options.regionListId).val('');
|
||||
$(this.options.regionInputId).val('');
|
||||
this._updateRegion($(e.target).val());
|
||||
}, this));
|
||||
|
||||
if (this.options.isCountryRequired) {
|
||||
this.element.addClass('required-entry');
|
||||
this.element.parents('div.field').addClass('required');
|
||||
}
|
||||
} else {
|
||||
this.element.parents('div.field').hide();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove options from dropdown list
|
||||
*
|
||||
* @param {Object} selectElement - jQuery object for dropdown list
|
||||
* @private
|
||||
*/
|
||||
_removeSelectOptions: function (selectElement) {
|
||||
selectElement.find('option').each(function (index) {
|
||||
if (index) {
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Render dropdown list
|
||||
* @param {Object} selectElement - jQuery object for dropdown list
|
||||
* @param {String} key - region code
|
||||
* @param {Object} value - region object
|
||||
* @private
|
||||
*/
|
||||
_renderSelectOption: function (selectElement, key, value) {
|
||||
selectElement.append($.proxy(function () {
|
||||
var name = value.name.replace(/[!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~]/g, '\\$&'),
|
||||
tmplData,
|
||||
tmpl;
|
||||
|
||||
if (value.code && $(name).is('span')) {
|
||||
key = value.code;
|
||||
value.name = $(name).text();
|
||||
}
|
||||
|
||||
tmplData = {
|
||||
value: key,
|
||||
title: value.name,
|
||||
isSelected: false
|
||||
};
|
||||
|
||||
if (this.options.defaultRegion === key) {
|
||||
tmplData.isSelected = true;
|
||||
}
|
||||
|
||||
tmpl = this.regionTmpl({
|
||||
data: tmplData
|
||||
});
|
||||
|
||||
return $(tmpl);
|
||||
}, this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Takes clearError callback function as first option
|
||||
* If no form is passed as option, look up the closest form and call clearError method.
|
||||
* @private
|
||||
*/
|
||||
_clearError: function () {
|
||||
var args = ['clearError', this.options.regionListId, this.options.regionInputId, this.options.postcodeId];
|
||||
|
||||
if (this.options.clearError && typeof this.options.clearError === 'function') {
|
||||
this.options.clearError.call(this);
|
||||
} else {
|
||||
if (!this.options.form) {
|
||||
this.options.form = this.element.closest('form').length ? $(this.element.closest('form')[0]) : null;
|
||||
}
|
||||
|
||||
this.options.form = $(this.options.form);
|
||||
|
||||
this.options.form && this.options.form.data('validator') &&
|
||||
this.options.form.validation.apply(this.options.form, _.compact(args));
|
||||
|
||||
// Clean up errors on region & zip fix
|
||||
$(this.options.regionInputId).removeClass('mage-error').parent().find('.mage-error').remove();
|
||||
$(this.options.regionListId).removeClass('mage-error').parent().find('.mage-error').remove();
|
||||
$(this.options.postcodeId).removeClass('mage-error').parent().find('.mage-error').remove();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update dropdown list based on the country selected
|
||||
*
|
||||
* @param {String} country - 2 uppercase letter for country code
|
||||
* @private
|
||||
*/
|
||||
_updateRegion: function (country) {
|
||||
// Clear validation error messages
|
||||
var regionList = $(this.options.regionListId),
|
||||
regionInput = $(this.options.regionInputId),
|
||||
postcode = $(this.options.postcodeId),
|
||||
label = regionList.parent().siblings('label'),
|
||||
container = regionList.parents('div.field'),
|
||||
regionsEntries,
|
||||
regionId,
|
||||
regionData;
|
||||
|
||||
this._clearError();
|
||||
this._checkRegionRequired(country);
|
||||
|
||||
// Populate state/province dropdown list if available or use input box
|
||||
if (this.options.regionJson[country]) {
|
||||
this._removeSelectOptions(regionList);
|
||||
regionsEntries = _.pairs(this.options.regionJson[country]);
|
||||
regionsEntries.sort(function (a, b) {
|
||||
return a[1].name > b[1].name ? 1 : -1;
|
||||
});
|
||||
$.each(regionsEntries, $.proxy(function (key, value) {
|
||||
regionId = value[0];
|
||||
regionData = value[1];
|
||||
this._renderSelectOption(regionList, regionId, regionData);
|
||||
}, this));
|
||||
|
||||
if (this.currentRegionOption) {
|
||||
regionList.val(this.currentRegionOption);
|
||||
}
|
||||
|
||||
if (this.setOption) {
|
||||
regionList.find('option').filter(function () {
|
||||
return this.text === regionInput.val();
|
||||
}).attr('selected', true);
|
||||
}
|
||||
|
||||
if (this.options.isRegionRequired) {
|
||||
regionList.addClass('required-entry').prop('disabled', false);
|
||||
container.addClass('required').show();
|
||||
} else {
|
||||
regionList.removeClass('required-entry validate-select').removeAttr('data-validate');
|
||||
container.removeClass('required');
|
||||
|
||||
if (!this.options.optionalRegionAllowed) { //eslint-disable-line max-depth
|
||||
regionList.hide();
|
||||
container.hide();
|
||||
} else {
|
||||
regionList.prop('disabled', false).show();
|
||||
}
|
||||
}
|
||||
|
||||
regionList.show();
|
||||
regionInput.hide();
|
||||
label.attr('for', regionList.attr('id'));
|
||||
} else {
|
||||
this._removeSelectOptions(regionList);
|
||||
|
||||
if (this.options.isRegionRequired) {
|
||||
regionInput.addClass('required-entry').prop('disabled', false);
|
||||
container.addClass('required').show();
|
||||
} else {
|
||||
if (!this.options.optionalRegionAllowed) { //eslint-disable-line max-depth
|
||||
regionInput.attr('disabled', 'disabled');
|
||||
container.hide();
|
||||
}
|
||||
container.removeClass('required');
|
||||
regionInput.removeClass('required-entry');
|
||||
}
|
||||
|
||||
regionList.removeClass('required-entry').prop('disabled', 'disabled').hide();
|
||||
regionInput.show();
|
||||
label.attr('for', regionInput.attr('id'));
|
||||
}
|
||||
|
||||
// If country is in optionalzip list, make postcode input not required
|
||||
if (this.options.isZipRequired) {
|
||||
$.inArray(country, this.options.countriesWithOptionalZip) >= 0 ?
|
||||
postcode.removeClass('required-entry').closest('.field').removeClass('required') :
|
||||
postcode.addClass('required-entry').closest('.field').addClass('required');
|
||||
}
|
||||
|
||||
// Add defaultvalue attribute to state/province select element
|
||||
regionList.attr('defaultvalue', this.options.defaultRegion);
|
||||
this.options.form.find('[type="submit"]').prop('disabled', false).show();
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if the selected country has a mandatory region selection
|
||||
*
|
||||
* @param {String} country - Code of the country - 2 uppercase letter for country code
|
||||
* @private
|
||||
*/
|
||||
_checkRegionRequired: function (country) {
|
||||
var self = this;
|
||||
|
||||
this.options.isRegionRequired = false;
|
||||
$.each(this.options.regionJson.config['regions_required'], function (index, elem) {
|
||||
if (elem === country) {
|
||||
self.options.isRegionRequired = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return $.mage.regionUpdater;
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Ui/js/modal/confirm',
|
||||
'jquery-ui-modules/widget',
|
||||
'mage/translate'
|
||||
], function ($, confirm) {
|
||||
'use strict';
|
||||
|
||||
$.widget('mage.shoppingCart', {
|
||||
/** @inheritdoc */
|
||||
_create: function () {
|
||||
var items, i, reload;
|
||||
|
||||
$(this.options.emptyCartButton).on('click', $.proxy(function () {
|
||||
this._confirmClearCart();
|
||||
}, this));
|
||||
items = $.find('[data-role="cart-item-qty"]');
|
||||
|
||||
for (i = 0; i < items.length; i++) {
|
||||
$(items[i]).on('keypress', $.proxy(function (event) { //eslint-disable-line no-loop-func
|
||||
var keyCode = event.keyCode ? event.keyCode : event.which;
|
||||
|
||||
if (keyCode == 13) { //eslint-disable-line eqeqeq
|
||||
$(this.options.emptyCartButton).attr('name', 'update_cart_action_temp');
|
||||
$(this.options.updateCartActionContainer)
|
||||
.attr('name', 'update_cart_action').attr('value', 'update_qty');
|
||||
|
||||
}
|
||||
}, this));
|
||||
}
|
||||
$(this.options.continueShoppingButton).on('click', $.proxy(function () {
|
||||
location.href = this.options.continueShoppingUrl;
|
||||
}, this));
|
||||
|
||||
$(document).on('ajax:removeFromCart', $.proxy(function () {
|
||||
reload = true;
|
||||
$('div.block.block-minicart').on('dropdowndialogclose', $.proxy(function () {
|
||||
if (reload === true) {
|
||||
location.reload();
|
||||
reload = false;
|
||||
}
|
||||
$('div.block.block-minicart').off('dropdowndialogclose');
|
||||
}));
|
||||
}, this));
|
||||
$(document).on('ajax:updateItemQty', $.proxy(function () {
|
||||
reload = true;
|
||||
$('div.block.block-minicart').on('dropdowndialogclose', $.proxy(function () {
|
||||
if (reload === true) {
|
||||
location.reload();
|
||||
reload = false;
|
||||
}
|
||||
$('div.block.block-minicart').off('dropdowndialogclose');
|
||||
}));
|
||||
}, this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Display confirmation modal for clearing the cart
|
||||
* @private
|
||||
*/
|
||||
_confirmClearCart: function () {
|
||||
var self = this;
|
||||
|
||||
confirm({
|
||||
content: $.mage.__('Are you sure you want to remove all items from your shopping cart?'),
|
||||
actions: {
|
||||
/**
|
||||
* Confirmation modal handler to execute clear cart action
|
||||
*/
|
||||
confirm: function () {
|
||||
self.clearCart();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Prepares the form and submit to clear the cart
|
||||
* @public
|
||||
*/
|
||||
clearCart: function () {
|
||||
$(this.options.emptyCartButton).attr('name', 'update_cart_action_temp');
|
||||
$(this.options.updateCartActionContainer)
|
||||
.attr('name', 'update_cart_action').attr('value', 'empty_cart');
|
||||
|
||||
if ($(this.options.emptyCartButton).parents('form').length > 0) {
|
||||
$(this.options.emptyCartButton).parents('form').trigger('submit');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $.mage.shoppingCart;
|
||||
});
|
||||
@@ -0,0 +1,351 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Customer/js/model/authentication-popup',
|
||||
'Magento_Customer/js/customer-data',
|
||||
'Magento_Ui/js/modal/alert',
|
||||
'Magento_Ui/js/modal/confirm',
|
||||
'underscore',
|
||||
'jquery-ui-modules/widget',
|
||||
'mage/decorate',
|
||||
'mage/collapsible',
|
||||
'mage/cookies',
|
||||
'jquery-ui-modules/effect-fade'
|
||||
], function ($, authenticationPopup, customerData, alert, confirm, _) {
|
||||
'use strict';
|
||||
|
||||
$.widget('mage.sidebar', {
|
||||
options: {
|
||||
isRecursive: true,
|
||||
minicart: {
|
||||
maxItemsVisible: 3
|
||||
}
|
||||
},
|
||||
scrollHeight: 0,
|
||||
shoppingCartUrl: window.checkout.shoppingCartUrl,
|
||||
|
||||
/**
|
||||
* Create sidebar.
|
||||
* @private
|
||||
*/
|
||||
_create: function () {
|
||||
this._initContent();
|
||||
},
|
||||
|
||||
/**
|
||||
* Update sidebar block.
|
||||
*/
|
||||
update: function () {
|
||||
$(this.options.targetElement).trigger('contentUpdated');
|
||||
this._calcHeight();
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_initContent: function () {
|
||||
var self = this,
|
||||
events = {};
|
||||
|
||||
this.element.decorate('list', this.options.isRecursive);
|
||||
|
||||
/**
|
||||
* @param {jQuery.Event} event
|
||||
*/
|
||||
events['click ' + this.options.button.close] = function (event) {
|
||||
event.stopPropagation();
|
||||
$(self.options.targetElement).dropdownDialog('close');
|
||||
};
|
||||
events['click ' + this.options.button.checkout] = $.proxy(function () {
|
||||
var cart = customerData.get('cart'),
|
||||
customer = customerData.get('customer'),
|
||||
element = $(this.options.button.checkout);
|
||||
|
||||
if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
|
||||
// set URL for redirect on successful login/registration. It's postprocessed on backend.
|
||||
$.cookie('login_redirect', this.options.url.checkout);
|
||||
|
||||
if (this.options.url.isRedirectRequired) {
|
||||
element.prop('disabled', true);
|
||||
location.href = this.options.url.loginUrl;
|
||||
} else {
|
||||
authenticationPopup.showModal();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
element.prop('disabled', true);
|
||||
location.href = this.options.url.checkout;
|
||||
}, this);
|
||||
|
||||
/**
|
||||
* @param {jQuery.Event} event
|
||||
*/
|
||||
events['click ' + this.options.button.remove] = function (event) {
|
||||
event.stopPropagation();
|
||||
confirm({
|
||||
content: self.options.confirmMessage,
|
||||
actions: {
|
||||
/** @inheritdoc */
|
||||
confirm: function () {
|
||||
self._removeItem($(event.currentTarget));
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
always: function (e) {
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {jQuery.Event} event
|
||||
*/
|
||||
events['keyup ' + this.options.item.qty] = function (event) {
|
||||
self._showItemButton($(event.target));
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {jQuery.Event} event
|
||||
*/
|
||||
events['change ' + this.options.item.qty] = function (event) {
|
||||
self._showItemButton($(event.target));
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {jQuery.Event} event
|
||||
*/
|
||||
events['click ' + this.options.item.button] = function (event) {
|
||||
event.stopPropagation();
|
||||
self._updateItemQty($(event.currentTarget));
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {jQuery.Event} event
|
||||
*/
|
||||
events['focusout ' + this.options.item.qty] = function (event) {
|
||||
self._validateQty($(event.currentTarget));
|
||||
};
|
||||
|
||||
this._on(this.element, events);
|
||||
this._calcHeight();
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} elem
|
||||
* @private
|
||||
*/
|
||||
_showItemButton: function (elem) {
|
||||
var itemId = elem.data('cart-item'),
|
||||
itemQty = elem.data('item-qty');
|
||||
|
||||
if (this._isValidQty(itemQty, elem.val())) {
|
||||
$('#update-cart-item-' + itemId).show('fade', 300);
|
||||
} else if (elem.val() == 0) { //eslint-disable-line eqeqeq
|
||||
this._hideItemButton(elem);
|
||||
} else {
|
||||
this._hideItemButton(elem);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {*} origin - origin qty. 'data-item-qty' attribute.
|
||||
* @param {*} changed - new qty.
|
||||
* @returns {Boolean}
|
||||
* @private
|
||||
*/
|
||||
_isValidQty: function (origin, changed) {
|
||||
return origin != changed && //eslint-disable-line eqeqeq
|
||||
changed.length > 0 &&
|
||||
changed - 0 == changed && //eslint-disable-line eqeqeq
|
||||
changed - 0 > 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} elem
|
||||
* @private
|
||||
*/
|
||||
_validateQty: function (elem) {
|
||||
var itemQty = elem.data('item-qty');
|
||||
|
||||
if (!this._isValidQty(itemQty, elem.val())) {
|
||||
elem.val(itemQty);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} elem
|
||||
* @private
|
||||
*/
|
||||
_hideItemButton: function (elem) {
|
||||
var itemId = elem.data('cart-item');
|
||||
|
||||
$('#update-cart-item-' + itemId).hide('fade', 300);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} elem
|
||||
* @private
|
||||
*/
|
||||
_updateItemQty: function (elem) {
|
||||
var itemId = elem.data('cart-item');
|
||||
|
||||
this._ajax(this.options.url.update, {
|
||||
'item_id': itemId,
|
||||
'item_qty': $('#cart-item-' + itemId + '-qty').val()
|
||||
}, elem, this._updateItemQtyAfter);
|
||||
},
|
||||
|
||||
/**
|
||||
* Update content after update qty
|
||||
*
|
||||
* @param {HTMLElement} elem
|
||||
*/
|
||||
_updateItemQtyAfter: function (elem) {
|
||||
var productData = this._getProductById(Number(elem.data('cart-item')));
|
||||
|
||||
if (!_.isUndefined(productData)) {
|
||||
$(document).trigger('ajax:updateCartItemQty');
|
||||
|
||||
if (window.location.href === this.shoppingCartUrl) {
|
||||
window.location.reload(false);
|
||||
}
|
||||
}
|
||||
this._hideItemButton(elem);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} elem
|
||||
* @private
|
||||
*/
|
||||
_removeItem: function (elem) {
|
||||
var itemId = elem.data('cart-item');
|
||||
|
||||
this._ajax(this.options.url.remove, {
|
||||
'item_id': itemId
|
||||
}, elem, this._removeItemAfter);
|
||||
},
|
||||
|
||||
/**
|
||||
* Update content after item remove
|
||||
*
|
||||
* @param {Object} elem
|
||||
* @private
|
||||
*/
|
||||
_removeItemAfter: function (elem) {
|
||||
var productData = this._getProductById(Number(elem.data('cart-item')));
|
||||
|
||||
if (!_.isUndefined(productData)) {
|
||||
$(document).trigger('ajax:removeFromCart', {
|
||||
productIds: [productData['product_id']],
|
||||
productInfo: [
|
||||
{
|
||||
'id': productData['product_id']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
if (window.location.href.indexOf(this.shoppingCartUrl) === 0) {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves product data by Id.
|
||||
*
|
||||
* @param {Number} productId - product Id
|
||||
* @returns {Object|undefined}
|
||||
* @private
|
||||
*/
|
||||
_getProductById: function (productId) {
|
||||
return _.find(customerData.get('cart')().items, function (item) {
|
||||
return productId === Number(item['item_id']);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} url - ajax url
|
||||
* @param {Object} data - post data for ajax call
|
||||
* @param {Object} elem - element that initiated the event
|
||||
* @param {Function} callback - callback method to execute after AJAX success
|
||||
*/
|
||||
_ajax: function (url, data, elem, callback) {
|
||||
$.extend(data, {
|
||||
'form_key': $.mage.cookies.get('form_key')
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: data,
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
context: this,
|
||||
|
||||
/** @inheritdoc */
|
||||
beforeSend: function () {
|
||||
elem.attr('disabled', 'disabled');
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
complete: function () {
|
||||
elem.attr('disabled', null);
|
||||
}
|
||||
})
|
||||
.done(function (response) {
|
||||
var msg;
|
||||
|
||||
if (response.success) {
|
||||
callback.call(this, elem, response);
|
||||
} else {
|
||||
msg = response['error_message'];
|
||||
|
||||
if (msg) {
|
||||
alert({
|
||||
content: msg
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.fail(function (error) {
|
||||
console.log(JSON.stringify(error));
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate height of minicart list
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_calcHeight: function () {
|
||||
var self = this,
|
||||
height = 0,
|
||||
counter = this.options.minicart.maxItemsVisible,
|
||||
target = $(this.options.minicart.list),
|
||||
outerHeight;
|
||||
|
||||
self.scrollHeight = 0;
|
||||
target.children().each(function () {
|
||||
|
||||
if ($(this).find('.options').length > 0) {
|
||||
$(this).collapsible();
|
||||
}
|
||||
outerHeight = $(this).outerHeight(true);
|
||||
|
||||
if (counter-- > 0) {
|
||||
height += outerHeight;
|
||||
}
|
||||
self.scrollHeight += outerHeight;
|
||||
});
|
||||
|
||||
target.parent().height(height);
|
||||
}
|
||||
});
|
||||
|
||||
return $.mage.sidebar;
|
||||
});
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'Magento_Ui/js/view/messages',
|
||||
'Magento_Checkout/js/model/authentication-messages'
|
||||
], function (Component, messageContainer) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
/** @inheritdoc */
|
||||
initialize: function (config) {
|
||||
return this._super(config, messageContainer);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'Magento_Ui/js/form/form',
|
||||
'Magento_Customer/js/action/login',
|
||||
'Magento_Customer/js/model/customer',
|
||||
'mage/validation',
|
||||
'Magento_Checkout/js/model/authentication-messages',
|
||||
'Magento_Checkout/js/model/full-screen-loader'
|
||||
], function ($, Component, loginAction, customer, validation, messageContainer, fullScreenLoader) {
|
||||
'use strict';
|
||||
|
||||
var checkoutConfig = window.checkoutConfig;
|
||||
|
||||
return Component.extend({
|
||||
isGuestCheckoutAllowed: checkoutConfig.isGuestCheckoutAllowed,
|
||||
isCustomerLoginRequired: checkoutConfig.isCustomerLoginRequired,
|
||||
registerUrl: checkoutConfig.registerUrl,
|
||||
forgotPasswordUrl: checkoutConfig.forgotPasswordUrl,
|
||||
autocomplete: checkoutConfig.autocomplete,
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/authentication'
|
||||
},
|
||||
|
||||
/**
|
||||
* Is login form enabled for current customer.
|
||||
*
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isActive: function () {
|
||||
return !customer.isLoggedIn();
|
||||
},
|
||||
|
||||
/**
|
||||
* Provide login action.
|
||||
*
|
||||
* @param {HTMLElement} loginForm
|
||||
*/
|
||||
login: function (loginForm) {
|
||||
var loginData = {},
|
||||
formDataArray = $(loginForm).serializeArray();
|
||||
|
||||
formDataArray.forEach(function (entry) {
|
||||
loginData[entry.name] = entry.value;
|
||||
});
|
||||
|
||||
if ($(loginForm).validation() &&
|
||||
$(loginForm).validation('isValid')
|
||||
) {
|
||||
fullScreenLoader.startLoader();
|
||||
loginAction(loginData, checkoutConfig.checkoutUrl, undefined, messageContainer).always(function () {
|
||||
fullScreenLoader.stopLoader();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,324 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'ko',
|
||||
'underscore',
|
||||
'Magento_Ui/js/form/form',
|
||||
'Magento_Customer/js/model/customer',
|
||||
'Magento_Customer/js/model/address-list',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/action/create-billing-address',
|
||||
'Magento_Checkout/js/action/select-billing-address',
|
||||
'Magento_Checkout/js/checkout-data',
|
||||
'Magento_Checkout/js/model/checkout-data-resolver',
|
||||
'Magento_Customer/js/customer-data',
|
||||
'Magento_Checkout/js/action/set-billing-address',
|
||||
'Magento_Ui/js/model/messageList',
|
||||
'mage/translate',
|
||||
'Magento_Checkout/js/model/billing-address-postcode-validator',
|
||||
'Magento_Checkout/js/model/address-converter'
|
||||
],
|
||||
function (
|
||||
ko,
|
||||
_,
|
||||
Component,
|
||||
customer,
|
||||
addressList,
|
||||
quote,
|
||||
createBillingAddress,
|
||||
selectBillingAddress,
|
||||
checkoutData,
|
||||
checkoutDataResolver,
|
||||
customerData,
|
||||
setBillingAddressAction,
|
||||
globalMessageList,
|
||||
$t,
|
||||
billingAddressPostcodeValidator,
|
||||
addressConverter
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
var lastSelectedBillingAddress = null,
|
||||
addressUpdated = false,
|
||||
addressEdited = false,
|
||||
countryData = customerData.get('directory-data'),
|
||||
addressOptions = addressList().filter(function (address) {
|
||||
return address.getType() === 'customer-address';
|
||||
});
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/billing-address',
|
||||
actionsTemplate: 'Magento_Checkout/billing-address/actions',
|
||||
formTemplate: 'Magento_Checkout/billing-address/form',
|
||||
detailsTemplate: 'Magento_Checkout/billing-address/details',
|
||||
links: {
|
||||
isAddressFormVisible: '${$.billingAddressListProvider}:isNewAddressSelected'
|
||||
}
|
||||
},
|
||||
currentBillingAddress: quote.billingAddress,
|
||||
customerHasAddresses: addressOptions.length > 0,
|
||||
|
||||
/**
|
||||
* Init component
|
||||
*/
|
||||
initialize: function () {
|
||||
this._super();
|
||||
quote.paymentMethod.subscribe(function () {
|
||||
checkoutDataResolver.resolveBillingAddress();
|
||||
}, this);
|
||||
billingAddressPostcodeValidator.initFields(this.get('name') + '.form-fields');
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {exports.initObservable}
|
||||
*/
|
||||
initObservable: function () {
|
||||
this._super()
|
||||
.observe({
|
||||
selectedAddress: null,
|
||||
isAddressDetailsVisible: quote.billingAddress() != null,
|
||||
isAddressFormVisible: !customer.isLoggedIn() || !addressOptions.length,
|
||||
isAddressSameAsShipping: false,
|
||||
saveInAddressBook: 1
|
||||
});
|
||||
|
||||
quote.billingAddress.subscribe(function (newAddress) {
|
||||
if (quote.isVirtual()) {
|
||||
this.isAddressSameAsShipping(false);
|
||||
} else {
|
||||
this.isAddressSameAsShipping(
|
||||
newAddress != null &&
|
||||
newAddress.getCacheKey() == quote.shippingAddress().getCacheKey() //eslint-disable-line eqeqeq
|
||||
);
|
||||
}
|
||||
|
||||
if (newAddress != null && newAddress.saveInAddressBook !== undefined) {
|
||||
this.saveInAddressBook(newAddress.saveInAddressBook);
|
||||
} else {
|
||||
this.saveInAddressBook(1);
|
||||
}
|
||||
this.isAddressDetailsVisible(true);
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
canUseShippingAddress: ko.computed(function () {
|
||||
return !quote.isVirtual() && quote.shippingAddress() && quote.shippingAddress().canUseForBilling();
|
||||
}),
|
||||
|
||||
/**
|
||||
* @param {Object} address
|
||||
* @return {*}
|
||||
*/
|
||||
addressOptionsText: function (address) {
|
||||
return address.getAddressInline();
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
useShippingAddress: function () {
|
||||
if (this.isAddressSameAsShipping()) {
|
||||
selectBillingAddress(quote.shippingAddress());
|
||||
this.updateAddresses(true);
|
||||
this.isAddressDetailsVisible(true);
|
||||
} else {
|
||||
lastSelectedBillingAddress = quote.billingAddress();
|
||||
quote.billingAddress(null);
|
||||
this.isAddressDetailsVisible(false);
|
||||
}
|
||||
checkoutData.setSelectedBillingAddress(null);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Update address action
|
||||
*/
|
||||
updateAddress: function () {
|
||||
var addressData, newBillingAddress;
|
||||
|
||||
addressUpdated = true;
|
||||
|
||||
if (this.selectedAddress() && !this.isAddressFormVisible()) {
|
||||
selectBillingAddress(this.selectedAddress());
|
||||
checkoutData.setSelectedBillingAddress(this.selectedAddress().getKey());
|
||||
} else {
|
||||
this.source.set('params.invalid', false);
|
||||
this.source.trigger(this.dataScopePrefix + '.data.validate');
|
||||
|
||||
if (this.source.get(this.dataScopePrefix + '.custom_attributes')) {
|
||||
this.source.trigger(this.dataScopePrefix + '.custom_attributes.data.validate');
|
||||
}
|
||||
|
||||
if (!this.source.get('params.invalid')) {
|
||||
addressData = this.source.get(this.dataScopePrefix);
|
||||
|
||||
if (customer.isLoggedIn() && !this.customerHasAddresses) { //eslint-disable-line max-depth
|
||||
this.saveInAddressBook(1);
|
||||
}
|
||||
addressData['save_in_address_book'] = this.saveInAddressBook() ? 1 : 0;
|
||||
newBillingAddress = createBillingAddress(addressData);
|
||||
// New address must be selected as a billing address
|
||||
selectBillingAddress(newBillingAddress);
|
||||
checkoutData.setSelectedBillingAddress(newBillingAddress.getKey());
|
||||
checkoutData.setNewCustomerBillingAddress(addressData);
|
||||
}
|
||||
}
|
||||
this.updateAddresses(true);
|
||||
},
|
||||
|
||||
/**
|
||||
* Edit address action
|
||||
*/
|
||||
editAddress: function () {
|
||||
addressUpdated = false;
|
||||
addressEdited = true;
|
||||
lastSelectedBillingAddress = quote.billingAddress();
|
||||
quote.billingAddress(null);
|
||||
this.isAddressDetailsVisible(false);
|
||||
},
|
||||
|
||||
/**
|
||||
* Cancel address edit action
|
||||
*/
|
||||
cancelAddressEdit: function () {
|
||||
addressUpdated = true;
|
||||
this.restoreBillingAddress();
|
||||
|
||||
if (quote.billingAddress()) {
|
||||
// restore 'Same As Shipping' checkbox state
|
||||
this.isAddressSameAsShipping(
|
||||
quote.billingAddress() != null &&
|
||||
quote.billingAddress().getCacheKey() == quote.shippingAddress().getCacheKey() && //eslint-disable-line
|
||||
!quote.isVirtual()
|
||||
);
|
||||
this.isAddressDetailsVisible(true);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Manage cancel button visibility
|
||||
*/
|
||||
canUseCancelBillingAddress: ko.computed(function () {
|
||||
return quote.billingAddress() || lastSelectedBillingAddress;
|
||||
}),
|
||||
|
||||
/**
|
||||
* Check if Billing Address Changes should be canceled
|
||||
*/
|
||||
needCancelBillingAddressChanges: function () {
|
||||
if (addressEdited && !addressUpdated) {
|
||||
this.cancelAddressEdit();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Restore billing address
|
||||
*/
|
||||
restoreBillingAddress: function () {
|
||||
var lastBillingAddress;
|
||||
|
||||
if (lastSelectedBillingAddress != null) {
|
||||
selectBillingAddress(lastSelectedBillingAddress);
|
||||
lastBillingAddress = addressConverter.quoteAddressToFormAddressData(lastSelectedBillingAddress);
|
||||
|
||||
checkoutData.setNewCustomerBillingAddress(lastBillingAddress);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Number} countryId
|
||||
* @return {*}
|
||||
*/
|
||||
getCountryName: function (countryId) {
|
||||
return countryData()[countryId] != undefined ? countryData()[countryId].name : ''; //eslint-disable-line
|
||||
},
|
||||
|
||||
/**
|
||||
* Trigger action to update shipping and billing addresses
|
||||
*
|
||||
* @param {Boolean} force
|
||||
*/
|
||||
updateAddresses: function (force) {
|
||||
force = !(typeof force === 'undefined' || force !== true);
|
||||
|
||||
if (force
|
||||
|| window.checkoutConfig.reloadOnBillingAddress
|
||||
|| !window.checkoutConfig.displayBillingOnPaymentMethod) {
|
||||
setBillingAddressAction(globalMessageList);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get code
|
||||
* @param {Object} parent
|
||||
* @returns {String}
|
||||
*/
|
||||
getCode: function (parent) {
|
||||
return _.isFunction(parent.getCode) ? parent.getCode() : 'shared';
|
||||
},
|
||||
|
||||
/**
|
||||
* Get customer attribute label
|
||||
*
|
||||
* @param {*} attribute
|
||||
* @returns {*}
|
||||
*/
|
||||
getCustomAttributeLabel: function (attribute) {
|
||||
var label;
|
||||
|
||||
if (typeof attribute === 'string') {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
if (attribute.label) {
|
||||
return attribute.label;
|
||||
}
|
||||
|
||||
if (_.isArray(attribute.value)) {
|
||||
label = _.map(attribute.value, function (value) {
|
||||
return this.getCustomAttributeOptionLabel(attribute['attribute_code'], value) || value;
|
||||
}, this).join(', ');
|
||||
} else if (typeof attribute.value === 'object') {
|
||||
label = _.map(Object.values(attribute.value)).join(', ');
|
||||
} else {
|
||||
label = this.getCustomAttributeOptionLabel(attribute['attribute_code'], attribute.value);
|
||||
}
|
||||
|
||||
return label || attribute.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get option label for given attribute code and option ID
|
||||
*
|
||||
* @param {String} attributeCode
|
||||
* @param {String} value
|
||||
* @returns {String|null}
|
||||
*/
|
||||
getCustomAttributeOptionLabel: function (attributeCode, value) {
|
||||
var option,
|
||||
label,
|
||||
options = this.source.get('customAttributes') || {};
|
||||
|
||||
if (options[attributeCode]) {
|
||||
option = _.findWhere(options[attributeCode], {
|
||||
value: value
|
||||
});
|
||||
|
||||
if (option) {
|
||||
label = option.label;
|
||||
}
|
||||
} else if (value.file !== null) {
|
||||
label = value.file;
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
});
|
||||
});
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'uiComponent',
|
||||
'Magento_Customer/js/model/address-list',
|
||||
'mage/translate',
|
||||
'Magento_Customer/js/model/customer'
|
||||
], function (Component, addressList, $t, customer) {
|
||||
'use strict';
|
||||
|
||||
var newAddressOption = {
|
||||
/**
|
||||
* Get new address label
|
||||
* @returns {String}
|
||||
*/
|
||||
getAddressInline: function () {
|
||||
return $t('New Address');
|
||||
},
|
||||
customerAddressId: null
|
||||
},
|
||||
addressOptions = addressList().filter(function (address) {
|
||||
return address.getType() === 'customer-address';
|
||||
}),
|
||||
addressDefaultIndex = addressOptions.findIndex(function (address) {
|
||||
return address.isDefaultBilling();
|
||||
});
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/billing-address',
|
||||
selectedAddress: null,
|
||||
isNewAddressSelected: false,
|
||||
addressOptions: addressOptions,
|
||||
exports: {
|
||||
selectedAddress: '${ $.parentName }:selectedAddress'
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {Object} Chainable.
|
||||
*/
|
||||
initConfig: function () {
|
||||
this._super();
|
||||
this.addressOptions.push(newAddressOption);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {exports.initObservable}
|
||||
*/
|
||||
initObservable: function () {
|
||||
this._super()
|
||||
.observe('selectedAddress isNewAddressSelected')
|
||||
.observe({
|
||||
isNewAddressSelected: !customer.isLoggedIn() || !addressOptions.length,
|
||||
selectedAddress: this.addressOptions[addressDefaultIndex]
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} address
|
||||
* @return {*}
|
||||
*/
|
||||
addressOptionsText: function (address) {
|
||||
return address.getAddressInline();
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} address
|
||||
*/
|
||||
onAddressChange: function (address) {
|
||||
this.isNewAddressSelected(address === newAddressOption);
|
||||
}
|
||||
});
|
||||
});
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'uiComponent'
|
||||
], function (Component) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
/**
|
||||
* Prepare the product name value to be rendered as HTML
|
||||
*
|
||||
* @param {String} productName
|
||||
* @return {String}
|
||||
*/
|
||||
getProductNameUnsanitizedHtml: function (productName) {
|
||||
// product name has already escaped on backend
|
||||
return productName;
|
||||
},
|
||||
|
||||
/**
|
||||
* Prepare the given option value to be rendered as HTML
|
||||
*
|
||||
* @param {String} optionValue
|
||||
* @return {String}
|
||||
*/
|
||||
getOptionValueUnsanitizedHtml: function (optionValue) {
|
||||
// option value has already escaped on backend
|
||||
return optionValue;
|
||||
}
|
||||
});
|
||||
});
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
define(
|
||||
[
|
||||
'jquery',
|
||||
'Magento_Ui/js/form/form',
|
||||
'Magento_Checkout/js/action/select-shipping-address',
|
||||
'Magento_Checkout/js/model/address-converter',
|
||||
'Magento_Checkout/js/model/cart/estimate-service',
|
||||
'Magento_Checkout/js/checkout-data',
|
||||
'Magento_Checkout/js/model/shipping-rates-validator',
|
||||
'uiRegistry',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/checkout-data-resolver',
|
||||
'Magento_Checkout/js/model/shipping-service',
|
||||
'mage/validation'
|
||||
],
|
||||
function (
|
||||
$,
|
||||
Component,
|
||||
selectShippingAddress,
|
||||
addressConverter,
|
||||
estimateService,
|
||||
checkoutData,
|
||||
shippingRatesValidator,
|
||||
registry,
|
||||
quote,
|
||||
checkoutDataResolver,
|
||||
shippingService
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/cart/shipping-estimation'
|
||||
},
|
||||
isVirtual: quote.isVirtual(),
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
initialize: function () {
|
||||
this._super();
|
||||
|
||||
// Prevent shipping methods showing none available whilst we resolve
|
||||
shippingService.isLoading(true);
|
||||
|
||||
registry.async('checkoutProvider')(function (checkoutProvider) {
|
||||
var address, estimatedAddress;
|
||||
|
||||
shippingService.isLoading(false);
|
||||
|
||||
checkoutDataResolver.resolveEstimationAddress();
|
||||
address = quote.isVirtual() ? quote.billingAddress() : quote.shippingAddress();
|
||||
|
||||
if (!address && quote.isVirtual()) {
|
||||
address = addressConverter.formAddressDataToQuoteAddress(
|
||||
checkoutData.getSelectedBillingAddress()
|
||||
);
|
||||
}
|
||||
|
||||
if (address) {
|
||||
estimatedAddress = address.isEditable() ?
|
||||
addressConverter.quoteAddressToFormAddressData(address) :
|
||||
{
|
||||
// only the following fields must be used by estimation form data provider
|
||||
'country_id': address.countryId,
|
||||
region: address.region,
|
||||
'region_id': address.regionId,
|
||||
postcode: address.postcode
|
||||
};
|
||||
checkoutProvider.set(
|
||||
'shippingAddress',
|
||||
$.extend({}, checkoutProvider.get('shippingAddress'), estimatedAddress)
|
||||
);
|
||||
}
|
||||
|
||||
if (!quote.isVirtual()) {
|
||||
checkoutProvider.on('shippingAddress', function (shippingAddressData) {
|
||||
//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
if (quote.shippingAddress().countryId !== shippingAddressData.country_id ||
|
||||
(shippingAddressData.postcode || shippingAddressData.region_id)
|
||||
) {
|
||||
checkoutData.setShippingAddressFromData(shippingAddressData);
|
||||
}
|
||||
//jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
});
|
||||
} else {
|
||||
checkoutProvider.on('shippingAddress', function (shippingAddressData) {
|
||||
checkoutData.setBillingAddressFromData(shippingAddressData);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
initElement: function (element) {
|
||||
this._super();
|
||||
|
||||
if (element.index === 'address-fieldsets') {
|
||||
shippingRatesValidator.bindChangeHandlers(element.elems(), true, 500);
|
||||
element.elems.subscribe(function (elems) {
|
||||
shippingRatesValidator.doElementBinding(elems[elems.length - 1], true, 500);
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns shipping rates for address
|
||||
* @returns void
|
||||
*/
|
||||
getEstimationInfo: function () {
|
||||
var addressData = null;
|
||||
|
||||
this.source.set('params.invalid', false);
|
||||
this.source.trigger('shippingAddress.data.validate');
|
||||
|
||||
if (!this.source.get('params.invalid')) {
|
||||
addressData = this.source.get('shippingAddress');
|
||||
selectShippingAddress(addressConverter.formAddressDataToQuoteAddress(addressData));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'ko',
|
||||
'underscore',
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/shipping-service',
|
||||
'Magento_Catalog/js/price-utils',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/action/select-shipping-method',
|
||||
'Magento_Checkout/js/checkout-data'
|
||||
], function (ko, _, Component, shippingService, priceUtils, quote, selectShippingMethodAction, checkoutData) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/cart/shipping-rates'
|
||||
},
|
||||
isVisible: ko.observable(!quote.isVirtual()),
|
||||
isLoading: shippingService.isLoading,
|
||||
shippingRates: shippingService.getShippingRates(),
|
||||
shippingRateGroups: ko.observableArray([]),
|
||||
selectedShippingMethod: ko.computed(function () {
|
||||
return quote.shippingMethod() ?
|
||||
quote.shippingMethod()['carrier_code'] + '_' + quote.shippingMethod()['method_code'] :
|
||||
null;
|
||||
}),
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
initObservable: function () {
|
||||
var self = this;
|
||||
|
||||
this._super();
|
||||
|
||||
this.shippingRates.subscribe(function (rates) {
|
||||
self.shippingRateGroups([]);
|
||||
_.each(rates, function (rate) {
|
||||
var carrierTitle = rate['carrier_title'];
|
||||
|
||||
if (self.shippingRateGroups.indexOf(carrierTitle) === -1) {
|
||||
self.shippingRateGroups.push(carrierTitle);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get shipping rates for specific group based on title.
|
||||
* @returns Array
|
||||
*/
|
||||
getRatesForGroup: function (shippingRateGroupTitle) {
|
||||
return _.filter(this.shippingRates(), function (rate) {
|
||||
return shippingRateGroupTitle === rate['carrier_title'];
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Format shipping price.
|
||||
* @returns {String}
|
||||
*/
|
||||
getFormattedPrice: function (price) {
|
||||
return priceUtils.formatPriceLocale(price, quote.getPriceFormat());
|
||||
},
|
||||
|
||||
/**
|
||||
* Set shipping method.
|
||||
* @param {String} methodData
|
||||
* @returns bool
|
||||
*/
|
||||
selectShippingMethod: function (methodData) {
|
||||
selectShippingMethodAction(methodData);
|
||||
checkoutData.setSelectedShippingRate(methodData['carrier_code'] + '_' + methodData['method_code']);
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/totals',
|
||||
'Magento_Checkout/js/model/shipping-service'
|
||||
], function ($, Component, totalsService, shippingService) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
isLoading: totalsService.isLoading,
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
initialize: function () {
|
||||
this._super();
|
||||
totalsService.totals.subscribe(function () {
|
||||
$(window).trigger('resize');
|
||||
});
|
||||
shippingService.getShippingRates().subscribe(function () {
|
||||
$(window).trigger('resize');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'Magento_Checkout/js/view/summary/abstract-total',
|
||||
'Magento_Checkout/js/model/quote'
|
||||
], function (Component, quote) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/cart/totals/customer-discount'
|
||||
},
|
||||
|
||||
/**
|
||||
* Get pure value.
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
getPureValue: function () {
|
||||
var totals = quote.getTotals()();
|
||||
var customerDiscount = 0;
|
||||
if (totals) {
|
||||
totals.total_segments.forEach(function (item){
|
||||
if (item.code === 'customer_discount') {
|
||||
customerDiscount = item.value
|
||||
return;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return customerDiscount
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*|String}
|
||||
*/
|
||||
getValue: function () {
|
||||
return this.getFormattedPrice(this.getPureValue());
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'Magento_Checkout/js/view/summary/shipping',
|
||||
'Magento_Checkout/js/model/quote'
|
||||
], function (Component, quote) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
isCalculated: function () {
|
||||
return !!quote.shippingMethod();
|
||||
}
|
||||
});
|
||||
});
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
define([
|
||||
'ko',
|
||||
'uiComponent',
|
||||
'Magento_Customer/js/customer-data'
|
||||
], function (ko, Component, customerData) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
displaySubtotal: ko.observable(true),
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
initialize: function () {
|
||||
this._super();
|
||||
this.cart = customerData.get('cart');
|
||||
}
|
||||
});
|
||||
});
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'Magento_Captcha/js/view/checkout/defaultCaptcha',
|
||||
'Magento_Captcha/js/model/captchaList',
|
||||
'underscore',
|
||||
'Magento_Checkout/js/model/payment/place-order-hooks'
|
||||
],
|
||||
function (defaultCaptcha, captchaList, _, placeOrderHooks) {
|
||||
'use strict';
|
||||
|
||||
return defaultCaptcha.extend({
|
||||
/** @inheritdoc */
|
||||
initialize: function () {
|
||||
var self = this,
|
||||
currentCaptcha;
|
||||
|
||||
this._super();
|
||||
currentCaptcha = captchaList.getCaptchaByFormId(this.formId);
|
||||
if (currentCaptcha != null) {
|
||||
currentCaptcha.setIsVisible(true);
|
||||
this.setCurrentCaptcha(currentCaptcha);
|
||||
placeOrderHooks.requestModifiers.push(function (headers) {
|
||||
if (self.isRequired()) {
|
||||
headers['X-Captcha'] = self.captchaValue()();
|
||||
}
|
||||
});
|
||||
if (self.isRequired()) {
|
||||
placeOrderHooks.afterRequestListeners.push(function () {
|
||||
self.refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
require([
|
||||
'jquery',
|
||||
'Magento_Customer/js/customer-data',
|
||||
'underscore',
|
||||
'domReady!'
|
||||
], function ($, customerData, _) {
|
||||
'use strict';
|
||||
|
||||
var selectors = {
|
||||
qtySelector: '#product_addtocart_form [name="qty"]',
|
||||
productIdSelector: '#product_addtocart_form [name="product"]',
|
||||
itemIdSelector: '#product_addtocart_form [name="item"]'
|
||||
},
|
||||
cartData = customerData.get('cart'),
|
||||
productId = $(selectors.productIdSelector).val(),
|
||||
itemId = $(selectors.itemIdSelector).val(),
|
||||
productQty,
|
||||
productQtyInput,
|
||||
|
||||
/**
|
||||
* Updates product's qty input value according to actual data
|
||||
*/
|
||||
updateQty = function () {
|
||||
|
||||
if (productQty || productQty === 0) {
|
||||
productQtyInput = productQtyInput || $(selectors.qtySelector);
|
||||
|
||||
if (productQtyInput && productQty.toString() !== productQtyInput.val()) {
|
||||
productQtyInput.val(productQty);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets productQty according to cart data from customer-data
|
||||
*
|
||||
* @param {Object} data - cart data from customer-data
|
||||
*/
|
||||
setProductQty = function (data) {
|
||||
var product;
|
||||
|
||||
if (!(data && data.items && data.items.length && productId)) {
|
||||
return;
|
||||
}
|
||||
product = _.find(data.items, function (item) {
|
||||
if (item['item_id'] === itemId) {
|
||||
return item['product_id'] === productId ||
|
||||
item['item_id'] === productId;
|
||||
}
|
||||
});
|
||||
|
||||
if (!product) {
|
||||
return;
|
||||
}
|
||||
productQty = product.qty;
|
||||
};
|
||||
|
||||
cartData.subscribe(function (updateCartData) {
|
||||
setProductQty(updateCartData);
|
||||
updateQty();
|
||||
});
|
||||
|
||||
setProductQty(cartData());
|
||||
updateQty();
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Catalog/js/price-utils',
|
||||
'Magento_Checkout/js/model/totals',
|
||||
'Magento_Checkout/js/model/sidebar'
|
||||
], function (Component, quote, priceUtils, totals, sidebarModel) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
isLoading: totals.isLoading,
|
||||
|
||||
/**
|
||||
* @return {Number}
|
||||
*/
|
||||
getQuantity: function () {
|
||||
if (totals.totals()) {
|
||||
return parseFloat(totals.totals()['items_qty']);
|
||||
}
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Number}
|
||||
*/
|
||||
getPureValue: function () {
|
||||
if (totals.totals()) {
|
||||
return parseFloat(totals.getSegment('grand_total').value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Show sidebar.
|
||||
*/
|
||||
showSidebar: function () {
|
||||
sidebarModel.show();
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {*} price
|
||||
* @return {*|String}
|
||||
*/
|
||||
getFormattedPrice: function (price) {
|
||||
return priceUtils.formatPriceLocale(price, quote.getPriceFormat());
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*|String}
|
||||
*/
|
||||
getValue: function () {
|
||||
return this.getFormattedPrice(this.getPureValue());
|
||||
}
|
||||
});
|
||||
});
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'uiComponent',
|
||||
'ko',
|
||||
'Magento_Customer/js/model/customer',
|
||||
'Magento_Customer/js/action/check-email-availability',
|
||||
'Magento_Customer/js/action/login',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/checkout-data',
|
||||
'Magento_Checkout/js/model/full-screen-loader',
|
||||
'mage/validation'
|
||||
], function ($, Component, ko, customer, checkEmailAvailability, loginAction, quote, checkoutData, fullScreenLoader) {
|
||||
'use strict';
|
||||
|
||||
var validatedEmail;
|
||||
|
||||
if (!checkoutData.getValidatedEmailValue() &&
|
||||
window.checkoutConfig.validatedEmailValue
|
||||
) {
|
||||
checkoutData.setInputFieldEmailValue(window.checkoutConfig.validatedEmailValue);
|
||||
checkoutData.setValidatedEmailValue(window.checkoutConfig.validatedEmailValue);
|
||||
}
|
||||
|
||||
validatedEmail = checkoutData.getValidatedEmailValue();
|
||||
|
||||
if (validatedEmail && !customer.isLoggedIn()) {
|
||||
quote.guestEmail = validatedEmail;
|
||||
}
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/form/element/email',
|
||||
email: checkoutData.getInputFieldEmailValue(),
|
||||
emailFocused: false,
|
||||
isLoading: false,
|
||||
isPasswordVisible: false,
|
||||
listens: {
|
||||
email: 'emailHasChanged',
|
||||
emailFocused: 'validateEmail'
|
||||
},
|
||||
ignoreTmpls: {
|
||||
email: true
|
||||
}
|
||||
},
|
||||
checkDelay: 2000,
|
||||
checkRequest: null,
|
||||
isEmailCheckComplete: null,
|
||||
isCustomerLoggedIn: customer.isLoggedIn,
|
||||
forgotPasswordUrl: window.checkoutConfig.forgotPasswordUrl,
|
||||
emailCheckTimeout: 0,
|
||||
emailInputId: '#customer-email',
|
||||
|
||||
/**
|
||||
* Initializes regular properties of instance.
|
||||
*
|
||||
* @returns {Object} Chainable.
|
||||
*/
|
||||
initConfig: function () {
|
||||
this._super();
|
||||
|
||||
this.isPasswordVisible = this.resolveInitialPasswordVisibility();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes observable properties of instance
|
||||
*
|
||||
* @returns {Object} Chainable.
|
||||
*/
|
||||
initObservable: function () {
|
||||
this._super()
|
||||
.observe(['email', 'emailFocused', 'isLoading', 'isPasswordVisible']);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback on changing email property
|
||||
*/
|
||||
emailHasChanged: function () {
|
||||
var self = this;
|
||||
|
||||
clearTimeout(this.emailCheckTimeout);
|
||||
|
||||
if (self.validateEmail()) {
|
||||
quote.guestEmail = self.email();
|
||||
checkoutData.setValidatedEmailValue(self.email());
|
||||
}
|
||||
this.emailCheckTimeout = setTimeout(function () {
|
||||
if (self.validateEmail()) {
|
||||
self.checkEmailAvailability();
|
||||
} else {
|
||||
self.isPasswordVisible(false);
|
||||
}
|
||||
}, self.checkDelay);
|
||||
|
||||
checkoutData.setInputFieldEmailValue(self.email());
|
||||
},
|
||||
|
||||
/**
|
||||
* Check email existing.
|
||||
*/
|
||||
checkEmailAvailability: function () {
|
||||
this.validateRequest();
|
||||
this.isEmailCheckComplete = $.Deferred();
|
||||
// Clean up errors on email
|
||||
$(this.emailInputId).removeClass('mage-error').parent().find('.mage-error').remove();
|
||||
this.isLoading(true);
|
||||
this.checkRequest = checkEmailAvailability(this.isEmailCheckComplete, this.email());
|
||||
|
||||
$.when(this.isEmailCheckComplete).done(function () {
|
||||
this.isPasswordVisible(false);
|
||||
checkoutData.setCheckedEmailValue('');
|
||||
}.bind(this)).fail(function () {
|
||||
this.isPasswordVisible(true);
|
||||
checkoutData.setCheckedEmailValue(this.email());
|
||||
}.bind(this)).always(function () {
|
||||
this.isLoading(false);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* If request has been sent -> abort it.
|
||||
* ReadyStates for request aborting:
|
||||
* 1 - The request has been set up
|
||||
* 2 - The request has been sent
|
||||
* 3 - The request is in process
|
||||
*/
|
||||
validateRequest: function () {
|
||||
if (this.checkRequest != null && $.inArray(this.checkRequest.readyState, [1, 2, 3])) {
|
||||
this.checkRequest.abort();
|
||||
this.checkRequest = null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Local email validation.
|
||||
*
|
||||
* @param {Boolean} focused - input focus.
|
||||
* @returns {Boolean} - validation result.
|
||||
*/
|
||||
validateEmail: function (focused) {
|
||||
var loginFormSelector = 'form[data-role=email-with-possible-login]',
|
||||
usernameSelector = loginFormSelector + ' input[name=username]',
|
||||
loginForm = $(loginFormSelector),
|
||||
validator,
|
||||
valid;
|
||||
|
||||
loginForm.validation();
|
||||
|
||||
if (focused === false && !!this.email()) {
|
||||
valid = !!$(usernameSelector).valid();
|
||||
|
||||
if (valid) {
|
||||
$(usernameSelector).removeAttr('aria-invalid aria-describedby');
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
if (loginForm.is(':visible')) {
|
||||
validator = loginForm.validate();
|
||||
|
||||
return validator.check(usernameSelector);
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Log in form submitting callback.
|
||||
*
|
||||
* @param {HTMLElement} loginForm - form element.
|
||||
*/
|
||||
login: function (loginForm) {
|
||||
var loginData = {},
|
||||
formDataArray = $(loginForm).serializeArray();
|
||||
|
||||
formDataArray.forEach(function (entry) {
|
||||
loginData[entry.name] = entry.value;
|
||||
});
|
||||
|
||||
if (this.isPasswordVisible() && $(loginForm).validation() && $(loginForm).validation('isValid')) {
|
||||
fullScreenLoader.startLoader();
|
||||
loginAction(loginData).always(function () {
|
||||
fullScreenLoader.stopLoader();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Resolves an initial state of a login form.
|
||||
*
|
||||
* @returns {Boolean} - initial visibility state.
|
||||
*/
|
||||
resolveInitialPasswordVisibility: function () {
|
||||
if (checkoutData.getInputFieldEmailValue() !== '' && checkoutData.getCheckedEmailValue() !== '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (checkoutData.getInputFieldEmailValue() !== '') {
|
||||
return checkoutData.getInputFieldEmailValue() === checkoutData.getCheckedEmailValue();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'uiComponent',
|
||||
'Magento_Customer/js/customer-data',
|
||||
'jquery',
|
||||
'ko',
|
||||
'underscore',
|
||||
'sidebar',
|
||||
'mage/translate',
|
||||
'mage/dropdown'
|
||||
], function (Component, customerData, $, ko, _) {
|
||||
'use strict';
|
||||
|
||||
var sidebarInitialized = false,
|
||||
addToCartCalls = 0,
|
||||
miniCart;
|
||||
|
||||
miniCart = $('[data-block=\'minicart\']');
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function initSidebar() {
|
||||
if (miniCart.data('mageSidebar')) {
|
||||
miniCart.sidebar('update');
|
||||
}
|
||||
|
||||
if (!$('[data-role=product-item]').length) {
|
||||
return false;
|
||||
}
|
||||
miniCart.trigger('contentUpdated');
|
||||
|
||||
if (sidebarInitialized) {
|
||||
return false;
|
||||
}
|
||||
sidebarInitialized = true;
|
||||
miniCart.sidebar({
|
||||
'targetElement': 'div.block.block-minicart',
|
||||
'url': {
|
||||
'checkout': window.checkout.checkoutUrl,
|
||||
'update': window.checkout.updateItemQtyUrl,
|
||||
'remove': window.checkout.removeItemUrl,
|
||||
'loginUrl': window.checkout.customerLoginUrl,
|
||||
'isRedirectRequired': window.checkout.isRedirectRequired
|
||||
},
|
||||
'button': {
|
||||
'checkout': '#top-cart-btn-checkout',
|
||||
'remove': '#mini-cart a.action.delete',
|
||||
'close': '#btn-minicart-close'
|
||||
},
|
||||
'showcart': {
|
||||
'parent': 'span.counter',
|
||||
'qty': 'span.counter-number',
|
||||
'label': 'span.counter-label'
|
||||
},
|
||||
'minicart': {
|
||||
'list': '#mini-cart',
|
||||
'content': '#minicart-content-wrapper',
|
||||
'qty': 'div.items-total',
|
||||
'subtotal': 'div.subtotal span.price',
|
||||
'maxItemsVisible': window.checkout.minicartMaxItemsVisible
|
||||
},
|
||||
'item': {
|
||||
'qty': ':input.cart-item-qty',
|
||||
'button': ':button.update-cart-item'
|
||||
},
|
||||
'confirmMessage': $.mage.__('Are you sure you would like to remove this item from the shopping cart?')
|
||||
});
|
||||
}
|
||||
|
||||
miniCart.on('dropdowndialogopen', function () {
|
||||
initSidebar();
|
||||
});
|
||||
|
||||
return Component.extend({
|
||||
shoppingCartUrl: window.checkout.shoppingCartUrl,
|
||||
maxItemsToDisplay: window.checkout.maxItemsToDisplay,
|
||||
cart: {},
|
||||
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
initialize: function () {
|
||||
var self = this,
|
||||
cartData = customerData.get('cart');
|
||||
|
||||
this.update(cartData());
|
||||
cartData.subscribe(function (updatedCart) {
|
||||
addToCartCalls--;
|
||||
this.isLoading(addToCartCalls > 0);
|
||||
sidebarInitialized = false;
|
||||
this.update(updatedCart);
|
||||
initSidebar();
|
||||
}, this);
|
||||
$('[data-block="minicart"]').on('contentLoading', function () {
|
||||
addToCartCalls++;
|
||||
self.isLoading(true);
|
||||
});
|
||||
|
||||
if (
|
||||
cartData().website_id !== window.checkout.websiteId && cartData().website_id !== undefined ||
|
||||
cartData().storeId !== window.checkout.storeId && cartData().storeId !== undefined
|
||||
) {
|
||||
customerData.reload(['cart'], false);
|
||||
}
|
||||
|
||||
return this._super();
|
||||
},
|
||||
//jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
|
||||
isLoading: ko.observable(false),
|
||||
initSidebar: initSidebar,
|
||||
|
||||
/**
|
||||
* Close mini shopping cart.
|
||||
*/
|
||||
closeMinicart: function () {
|
||||
$('[data-block="minicart"]').find('[data-role="dropdownDialog"]').dropdownDialog('close');
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} productType
|
||||
* @return {*|String}
|
||||
*/
|
||||
getItemRenderer: function (productType) {
|
||||
return this.itemRenderer[productType] || 'defaultRenderer';
|
||||
},
|
||||
|
||||
/**
|
||||
* Update mini shopping cart content.
|
||||
*
|
||||
* @param {Object} updatedCart
|
||||
* @returns void
|
||||
*/
|
||||
update: function (updatedCart) {
|
||||
_.each(updatedCart, function (value, key) {
|
||||
if (!this.cart.hasOwnProperty(key)) {
|
||||
this.cart[key] = ko.observable();
|
||||
}
|
||||
this.cart[key](value);
|
||||
}, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get cart param by name.
|
||||
*
|
||||
* @param {String} name
|
||||
* @returns {*}
|
||||
*/
|
||||
getCartParamUnsanitizedHtml: function (name) {
|
||||
if (!_.isUndefined(name)) {
|
||||
if (!this.cart.hasOwnProperty(name)) {
|
||||
this.cart[name] = ko.observable();
|
||||
}
|
||||
}
|
||||
|
||||
return this.cart[name]();
|
||||
},
|
||||
|
||||
/**
|
||||
* @deprecated please use getCartParamUnsanitizedHtml.
|
||||
* @param {String} name
|
||||
* @returns {*}
|
||||
*/
|
||||
getCartParam: function (name) {
|
||||
return this.getCartParamUnsanitizedHtml(name);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns array of cart items, limited by 'maxItemsToDisplay' setting
|
||||
* @returns []
|
||||
*/
|
||||
getCartItems: function () {
|
||||
var items = this.getCartParamUnsanitizedHtml('items') || [];
|
||||
|
||||
items = items.slice(parseInt(-this.maxItemsToDisplay, 10));
|
||||
|
||||
return items;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns count of cart line items
|
||||
* @returns {Number}
|
||||
*/
|
||||
getCartLineItemsCount: function () {
|
||||
var items = this.getCartParamUnsanitizedHtml('items') || [];
|
||||
|
||||
return parseInt(items.length, 10);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'uiComponent',
|
||||
'ko',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/step-navigator',
|
||||
'Magento_Checkout/js/model/payment-service',
|
||||
'Magento_Checkout/js/model/payment/method-converter',
|
||||
'Magento_Checkout/js/action/get-payment-information',
|
||||
'Magento_Checkout/js/model/checkout-data-resolver',
|
||||
'mage/translate'
|
||||
], function (
|
||||
$,
|
||||
_,
|
||||
Component,
|
||||
ko,
|
||||
quote,
|
||||
stepNavigator,
|
||||
paymentService,
|
||||
methodConverter,
|
||||
getPaymentInformation,
|
||||
checkoutDataResolver,
|
||||
$t
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
/** Set payment methods to collection */
|
||||
paymentService.setPaymentMethods(methodConverter(window.checkoutConfig.paymentMethods));
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/payment',
|
||||
activeMethod: ''
|
||||
},
|
||||
isVisible: ko.observable(quote.isVirtual()),
|
||||
quoteIsVirtual: quote.isVirtual(),
|
||||
isPaymentMethodsAvailable: ko.computed(function () {
|
||||
return paymentService.getAvailablePaymentMethods().length > 0;
|
||||
}),
|
||||
|
||||
/** @inheritdoc */
|
||||
initialize: function () {
|
||||
this._super();
|
||||
checkoutDataResolver.resolvePaymentMethod();
|
||||
stepNavigator.registerStep(
|
||||
'payment',
|
||||
null,
|
||||
$t('Review & Payments'),
|
||||
this.isVisible,
|
||||
_.bind(this.navigate, this),
|
||||
this.sortOrder
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Navigate method.
|
||||
*/
|
||||
navigate: function () {
|
||||
var self = this;
|
||||
|
||||
if (!self.hasShippingMethod()) {
|
||||
this.isVisible(false);
|
||||
stepNavigator.setHash('shipping');
|
||||
} else {
|
||||
getPaymentInformation().done(function () {
|
||||
self.isVisible(true);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
hasShippingMethod: function () {
|
||||
return window.checkoutConfig.selectedShippingMethod !== null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getFormKey: function () {
|
||||
return window.checkoutConfig.formKey;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,246 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'ko',
|
||||
'jquery',
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/action/place-order',
|
||||
'Magento_Checkout/js/action/select-payment-method',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Customer/js/model/customer',
|
||||
'Magento_Checkout/js/model/payment-service',
|
||||
'Magento_Checkout/js/checkout-data',
|
||||
'Magento_Checkout/js/model/checkout-data-resolver',
|
||||
'uiRegistry',
|
||||
'Magento_Checkout/js/model/payment/additional-validators',
|
||||
'Magento_Ui/js/model/messages',
|
||||
'uiLayout',
|
||||
'Magento_Checkout/js/action/redirect-on-success',
|
||||
'Magento_Checkout/js/model/step-navigator',
|
||||
], function (
|
||||
ko,
|
||||
$,
|
||||
Component,
|
||||
placeOrderAction,
|
||||
selectPaymentMethodAction,
|
||||
quote,
|
||||
customer,
|
||||
paymentService,
|
||||
checkoutData,
|
||||
checkoutDataResolver,
|
||||
registry,
|
||||
additionalValidators,
|
||||
Messages,
|
||||
layout,
|
||||
redirectOnSuccessAction,
|
||||
stepNavigator
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
redirectAfterPlaceOrder: true,
|
||||
isPlaceOrderActionAllowed: ko.observable(quote.billingAddress() != null),
|
||||
|
||||
/**
|
||||
* After place order callback
|
||||
*/
|
||||
afterPlaceOrder: function () {
|
||||
// Override this function and put after place order logic here
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize view.
|
||||
*
|
||||
* @return {exports}
|
||||
*/
|
||||
initialize: function () {
|
||||
var billingAddressCode,
|
||||
billingAddressData,
|
||||
defaultAddressData;
|
||||
|
||||
this._super().initChildren();
|
||||
quote.billingAddress.subscribe(function (address) {
|
||||
this.isPlaceOrderActionAllowed(address !== null);
|
||||
}, this);
|
||||
checkoutDataResolver.resolveBillingAddress();
|
||||
|
||||
billingAddressCode = 'billingAddress' + this.getCode();
|
||||
registry.async('checkoutProvider')(function (checkoutProvider) {
|
||||
defaultAddressData = checkoutProvider.get(billingAddressCode);
|
||||
|
||||
if (defaultAddressData === undefined) {
|
||||
// Skip if payment does not have a billing address form
|
||||
return;
|
||||
}
|
||||
billingAddressData = checkoutData.getBillingAddressFromData();
|
||||
|
||||
if (billingAddressData) {
|
||||
checkoutProvider.set(
|
||||
billingAddressCode,
|
||||
$.extend(true, {}, defaultAddressData, billingAddressData)
|
||||
);
|
||||
}
|
||||
checkoutProvider.on(billingAddressCode, function (providerBillingAddressData) {
|
||||
checkoutData.setBillingAddressFromData(providerBillingAddressData);
|
||||
}, billingAddressCode);
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize child elements
|
||||
*
|
||||
* @returns {Component} Chainable.
|
||||
*/
|
||||
initChildren: function () {
|
||||
this.messageContainer = new Messages();
|
||||
this.createMessagesComponent();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Create child message renderer component
|
||||
*
|
||||
* @returns {Component} Chainable.
|
||||
*/
|
||||
createMessagesComponent: function () {
|
||||
|
||||
var messagesComponent = {
|
||||
parent: this.name,
|
||||
name: this.name + '.messages',
|
||||
displayArea: 'messages',
|
||||
component: 'Magento_Ui/js/view/messages',
|
||||
config: {
|
||||
messageContainer: this.messageContainer
|
||||
}
|
||||
};
|
||||
|
||||
layout([messagesComponent]);
|
||||
|
||||
return this;
|
||||
},
|
||||
goToPrevStep: function () {
|
||||
stepNavigator.navigateTo('shipping');
|
||||
},
|
||||
|
||||
/**
|
||||
* Place order.
|
||||
*/
|
||||
placeOrder: function (data, event) {
|
||||
var self = this;
|
||||
|
||||
if (event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (this.validate() &&
|
||||
additionalValidators.validate() &&
|
||||
this.isPlaceOrderActionAllowed() === true
|
||||
) {
|
||||
this.isPlaceOrderActionAllowed(false);
|
||||
|
||||
this.getPlaceOrderDeferredObject()
|
||||
.done(
|
||||
function () {
|
||||
self.afterPlaceOrder();
|
||||
|
||||
if (self.redirectAfterPlaceOrder) {
|
||||
redirectOnSuccessAction.execute();
|
||||
}
|
||||
}
|
||||
).always(
|
||||
function () {
|
||||
self.isPlaceOrderActionAllowed(true);
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getPlaceOrderDeferredObject: function () {
|
||||
return $.when(
|
||||
placeOrderAction(this.getData(), this.messageContainer)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
selectPaymentMethod: function () {
|
||||
selectPaymentMethodAction(this.getData());
|
||||
checkoutData.setSelectedPaymentMethod(this.item.method);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
isChecked: ko.computed(function () {
|
||||
return quote.paymentMethod() ? quote.paymentMethod().method : null;
|
||||
}),
|
||||
|
||||
isRadioButtonVisible: ko.computed(function () {
|
||||
return paymentService.getAvailablePaymentMethods().length !== 1;
|
||||
}),
|
||||
|
||||
/**
|
||||
* Get payment method data
|
||||
*/
|
||||
getData: function () {
|
||||
return {
|
||||
'method': this.item.method,
|
||||
'po_number': null,
|
||||
'additional_data': null
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Get payment method type.
|
||||
*/
|
||||
getTitle: function () {
|
||||
return this.item.title;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get payment method code.
|
||||
*/
|
||||
getCode: function () {
|
||||
return this.item.method;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
validate: function () {
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
*/
|
||||
getBillingAddressFormName: function () {
|
||||
return 'billing-address-form-' + this.item.method;
|
||||
},
|
||||
|
||||
/**
|
||||
* Dispose billing address subscriptions
|
||||
*/
|
||||
disposeSubscriptions: function () {
|
||||
// dispose all active subscriptions
|
||||
var billingAddressCode = 'billingAddress' + this.getCode();
|
||||
|
||||
registry.async('checkoutProvider')(function (checkoutProvider) {
|
||||
checkoutProvider.off(billingAddressCode);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
define(
|
||||
[
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/payment/additional-validators',
|
||||
'Magento_Checkout/js/model/customer-email-validator'
|
||||
],
|
||||
function (Component, additionalValidators, agreementValidator) {
|
||||
'use strict';
|
||||
|
||||
additionalValidators.registerValidator(agreementValidator);
|
||||
|
||||
return Component.extend({});
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,230 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'underscore',
|
||||
'ko',
|
||||
'mageUtils',
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/payment/method-list',
|
||||
'Magento_Checkout/js/model/payment/renderer-list',
|
||||
'uiLayout',
|
||||
'Magento_Checkout/js/model/checkout-data-resolver',
|
||||
'mage/translate',
|
||||
'uiRegistry'
|
||||
], function (_, ko, utils, Component, paymentMethods, rendererList, layout, checkoutDataResolver, $t, registry) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/payment-methods/list',
|
||||
visible: paymentMethods().length > 0,
|
||||
configDefaultGroup: {
|
||||
name: 'methodGroup',
|
||||
component: 'Magento_Checkout/js/model/payment/method-group'
|
||||
},
|
||||
paymentGroupsList: [],
|
||||
defaultGroupTitle: $t('Select a new payment method')
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize view.
|
||||
*
|
||||
* @returns {Component} Chainable.
|
||||
*/
|
||||
initialize: function () {
|
||||
this._super().initDefaulGroup().initChildren();
|
||||
paymentMethods.subscribe(
|
||||
function (changes) {
|
||||
checkoutDataResolver.resolvePaymentMethod();
|
||||
//remove renderer for "deleted" payment methods
|
||||
_.each(changes, function (change) {
|
||||
if (change.status === 'deleted') {
|
||||
this.removeRenderer(change.value.method);
|
||||
}
|
||||
}, this);
|
||||
//add renderer for "added" payment methods
|
||||
_.each(changes, function (change) {
|
||||
if (change.status === 'added') {
|
||||
this.createRenderer(change.value);
|
||||
}
|
||||
}, this);
|
||||
}, this, 'arrayChange');
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
initObservable: function () {
|
||||
this._super().
|
||||
observe(['paymentGroupsList']);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates default group
|
||||
*
|
||||
* @returns {Component} Chainable.
|
||||
*/
|
||||
initDefaulGroup: function () {
|
||||
layout([
|
||||
this.configDefaultGroup
|
||||
]);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Create renders for child payment methods.
|
||||
*
|
||||
* @returns {Component} Chainable.
|
||||
*/
|
||||
initChildren: function () {
|
||||
var self = this;
|
||||
|
||||
_.each(paymentMethods(), function (paymentMethodData) {
|
||||
self.createRenderer(paymentMethodData);
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns
|
||||
*/
|
||||
createComponent: function (payment) {
|
||||
var rendererTemplate,
|
||||
rendererComponent,
|
||||
templateData;
|
||||
|
||||
templateData = {
|
||||
parentName: this.name,
|
||||
name: payment.name
|
||||
};
|
||||
rendererTemplate = {
|
||||
parent: '${ $.$data.parentName }',
|
||||
name: '${ $.$data.name }',
|
||||
displayArea: payment.displayArea,
|
||||
component: payment.component
|
||||
};
|
||||
rendererComponent = utils.template(rendererTemplate, templateData);
|
||||
utils.extend(rendererComponent, {
|
||||
item: payment.item,
|
||||
config: payment.config
|
||||
});
|
||||
|
||||
return rendererComponent;
|
||||
},
|
||||
|
||||
/**
|
||||
* Create renderer.
|
||||
*
|
||||
* @param {Object} paymentMethodData
|
||||
*/
|
||||
createRenderer: function (paymentMethodData) {
|
||||
var isRendererForMethod = false,
|
||||
currentGroup;
|
||||
|
||||
registry.get(this.configDefaultGroup.name, function (defaultGroup) {
|
||||
_.each(rendererList(), function (renderer) {
|
||||
|
||||
if (renderer.hasOwnProperty('typeComparatorCallback') &&
|
||||
typeof renderer.typeComparatorCallback == 'function'
|
||||
) {
|
||||
isRendererForMethod = renderer.typeComparatorCallback(renderer.type, paymentMethodData.method);
|
||||
} else {
|
||||
isRendererForMethod = renderer.type === paymentMethodData.method;
|
||||
}
|
||||
|
||||
if (isRendererForMethod) {
|
||||
currentGroup = renderer.group ? renderer.group : defaultGroup;
|
||||
|
||||
this.collectPaymentGroups(currentGroup);
|
||||
|
||||
layout([
|
||||
this.createComponent(
|
||||
{
|
||||
config: renderer.config,
|
||||
component: renderer.component,
|
||||
name: renderer.type,
|
||||
method: paymentMethodData.method,
|
||||
item: paymentMethodData,
|
||||
displayArea: currentGroup.displayArea
|
||||
}
|
||||
)]);
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Collects unique groups of available payment methods
|
||||
*
|
||||
* @param {Object} group
|
||||
*/
|
||||
collectPaymentGroups: function (group) {
|
||||
var groupsList = this.paymentGroupsList(),
|
||||
isGroupExists = _.some(groupsList, function (existsGroup) {
|
||||
return existsGroup.alias === group.alias;
|
||||
});
|
||||
|
||||
if (!isGroupExists) {
|
||||
groupsList.push(group);
|
||||
groupsList = _.sortBy(groupsList, function (existsGroup) {
|
||||
return existsGroup.sortOrder;
|
||||
});
|
||||
this.paymentGroupsList(groupsList);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns payment group title
|
||||
*
|
||||
* @param {Object} group
|
||||
* @returns {String}
|
||||
*/
|
||||
getGroupTitle: function (group) {
|
||||
var title = group().title;
|
||||
|
||||
if (group().isDefault() && this.paymentGroupsList().length > 1) {
|
||||
title = this.defaultGroupTitle;
|
||||
}
|
||||
|
||||
return title;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if at least one payment method available
|
||||
*
|
||||
* @returns {String}
|
||||
*/
|
||||
isPaymentMethodsAvailable: function () {
|
||||
return _.some(this.paymentGroupsList(), function (group) {
|
||||
return this.regionHasElements(group.displayArea);
|
||||
}, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove view renderer.
|
||||
*
|
||||
* @param {String} paymentMethodCode
|
||||
*/
|
||||
removeRenderer: function (paymentMethodCode) {
|
||||
var items;
|
||||
|
||||
_.each(this.paymentGroupsList(), function (group) {
|
||||
items = this.getRegion(group.displayArea);
|
||||
|
||||
_.find(items(), function (value) {
|
||||
if (value.item.method.indexOf(paymentMethodCode) === 0) {
|
||||
value.disposeSubscriptions();
|
||||
value.destroy();
|
||||
}
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'ko',
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/step-navigator',
|
||||
'Magento_Checkout/js/view/billing-address'
|
||||
], function ($, _, ko, Component, stepNavigator, billingAddress) {
|
||||
'use strict';
|
||||
|
||||
var steps = stepNavigator.steps;
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/progress-bar',
|
||||
visible: true
|
||||
},
|
||||
steps: steps,
|
||||
|
||||
/** @inheritdoc */
|
||||
initialize: function () {
|
||||
var stepsValue;
|
||||
|
||||
this._super();
|
||||
window.addEventListener('hashchange', _.bind(stepNavigator.handleHash, stepNavigator));
|
||||
|
||||
if (!window.location.hash) {
|
||||
stepsValue = stepNavigator.steps();
|
||||
|
||||
if (stepsValue.length) {
|
||||
stepNavigator.setHash(stepsValue.sort(stepNavigator.sortItems)[0].code);
|
||||
}
|
||||
}
|
||||
|
||||
stepNavigator.handleHash();
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {*} itemOne
|
||||
* @param {*} itemTwo
|
||||
* @return {*|Number}
|
||||
*/
|
||||
sortItems: function (itemOne, itemTwo) {
|
||||
return stepNavigator.sortItems(itemOne, itemTwo);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} step
|
||||
*/
|
||||
navigateTo: function (step) {
|
||||
if (step.code === 'shipping') {
|
||||
billingAddress().needCancelBillingAddressChanges();
|
||||
}
|
||||
stepNavigator.navigateTo(step.code);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} item
|
||||
* @return {*|Boolean}
|
||||
*/
|
||||
isProcessed: function (item) {
|
||||
return stepNavigator.isProcessed(item.code);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'uiComponent',
|
||||
'Magento_Ui/js/model/messageList'
|
||||
], function ($, Component, messageList) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/registration',
|
||||
accountCreated: false,
|
||||
creationStarted: false,
|
||||
isFormVisible: true
|
||||
},
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
initObservable: function () {
|
||||
this._super()
|
||||
.observe('accountCreated')
|
||||
.observe('isFormVisible')
|
||||
.observe('creationStarted');
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getEmailAddress: function () {
|
||||
return this.email;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
getUrl: function () {
|
||||
return this.registrationUrl;
|
||||
},
|
||||
|
||||
/**
|
||||
* Create new user account.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
createAccount: function () {
|
||||
this.creationStarted(true);
|
||||
$.post(
|
||||
this.registrationUrl
|
||||
).done(
|
||||
function (response) {
|
||||
|
||||
if (response.errors == false) { //eslint-disable-line eqeqeq
|
||||
this.accountCreated(true);
|
||||
} else {
|
||||
messageList.addErrorMessage(response);
|
||||
}
|
||||
this.isFormVisible(false);
|
||||
}.bind(this)
|
||||
).fail(
|
||||
function (response) {
|
||||
this.accountCreated(false);
|
||||
this.isFormVisible(false);
|
||||
messageList.addErrorMessage(response);
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'ko',
|
||||
'uiComponent',
|
||||
'underscore',
|
||||
'Magento_Checkout/js/action/select-shipping-address',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/shipping-address/form-popup-state',
|
||||
'Magento_Checkout/js/checkout-data',
|
||||
'Magento_Customer/js/customer-data'
|
||||
], function ($, ko, Component, _, selectShippingAddressAction, quote, formPopUpState, checkoutData, customerData) {
|
||||
'use strict';
|
||||
|
||||
var countryData = customerData.get('directory-data');
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/shipping-address/address-renderer/default'
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
initObservable: function () {
|
||||
this._super();
|
||||
this.isSelected = ko.computed(function () {
|
||||
var isSelected = false,
|
||||
shippingAddress = quote.shippingAddress();
|
||||
|
||||
if (shippingAddress) {
|
||||
isSelected = shippingAddress.getKey() == this.address().getKey(); //eslint-disable-line eqeqeq
|
||||
}
|
||||
|
||||
return isSelected;
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} countryId
|
||||
* @return {String}
|
||||
*/
|
||||
getCountryName: function (countryId) {
|
||||
return countryData()[countryId] != undefined ? countryData()[countryId].name : ''; //eslint-disable-line
|
||||
},
|
||||
|
||||
/**
|
||||
* Get customer attribute label
|
||||
*
|
||||
* @param {*} attribute
|
||||
* @returns {*}
|
||||
*/
|
||||
getCustomAttributeLabel: function (attribute) {
|
||||
var label;
|
||||
|
||||
if (typeof attribute === 'string') {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
if (attribute.label) {
|
||||
return attribute.label;
|
||||
}
|
||||
|
||||
if (_.isArray(attribute.value)) {
|
||||
label = _.map(attribute.value, function (value) {
|
||||
return this.getCustomAttributeOptionLabel(attribute['attribute_code'], value) || value;
|
||||
}, this).join(', ');
|
||||
} else if (typeof attribute.value === 'object') {
|
||||
label = _.map(Object.values(attribute.value)).join(', ');
|
||||
} else {
|
||||
label = this.getCustomAttributeOptionLabel(attribute['attribute_code'], attribute.value);
|
||||
}
|
||||
|
||||
return label || attribute.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get option label for given attribute code and option ID
|
||||
*
|
||||
* @param {String} attributeCode
|
||||
* @param {String} value
|
||||
* @returns {String|null}
|
||||
*/
|
||||
getCustomAttributeOptionLabel: function (attributeCode, value) {
|
||||
var option,
|
||||
label,
|
||||
options = this.source.get('customAttributes') || {};
|
||||
|
||||
if (options[attributeCode]) {
|
||||
option = _.findWhere(options[attributeCode], {
|
||||
value: value
|
||||
});
|
||||
|
||||
if (option) {
|
||||
label = option.label;
|
||||
}
|
||||
} else if (value.file !== null) {
|
||||
label = value.file;
|
||||
}
|
||||
|
||||
return label;
|
||||
},
|
||||
|
||||
/** Set selected customer shipping address */
|
||||
selectAddress: function () {
|
||||
selectShippingAddressAction(this.address());
|
||||
checkoutData.setSelectedShippingAddress(this.address().getKey());
|
||||
},
|
||||
|
||||
/**
|
||||
* Edit address.
|
||||
*/
|
||||
editAddress: function () {
|
||||
formPopUpState.isVisible(true);
|
||||
this.showPopup();
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Show popup.
|
||||
*/
|
||||
showPopup: function () {
|
||||
$('[data-open-modal="opc-new-shipping-address"]').trigger('click');
|
||||
}
|
||||
});
|
||||
});
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'underscore',
|
||||
'ko',
|
||||
'mageUtils',
|
||||
'uiComponent',
|
||||
'uiLayout',
|
||||
'Magento_Customer/js/model/address-list'
|
||||
], function (_, ko, utils, Component, layout, addressList) {
|
||||
'use strict';
|
||||
|
||||
var defaultRendererTemplate = {
|
||||
parent: '${ $.$data.parentName }',
|
||||
name: '${ $.$data.name }',
|
||||
component: 'Magento_Checkout/js/view/shipping-address/address-renderer/default',
|
||||
provider: 'checkoutProvider'
|
||||
};
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/shipping-address/list',
|
||||
visible: addressList().length > 0,
|
||||
rendererTemplates: []
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
initialize: function () {
|
||||
this._super()
|
||||
.initChildren();
|
||||
|
||||
addressList.subscribe(function (changes) {
|
||||
var self = this;
|
||||
|
||||
changes.forEach(function (change) {
|
||||
if (change.status === 'added') {
|
||||
self.createRendererComponent(change.value, change.index);
|
||||
}
|
||||
});
|
||||
},
|
||||
this,
|
||||
'arrayChange'
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
initConfig: function () {
|
||||
this._super();
|
||||
// the list of child components that are responsible for address rendering
|
||||
this.rendererComponents = [];
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
initChildren: function () {
|
||||
_.each(addressList(), this.createRendererComponent, this);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Create new component that will render given address in the address list
|
||||
*
|
||||
* @param {Object} address
|
||||
* @param {*} index
|
||||
*/
|
||||
createRendererComponent: function (address, index) {
|
||||
var rendererTemplate, templateData, rendererComponent;
|
||||
|
||||
if (index in this.rendererComponents) {
|
||||
this.rendererComponents[index].address(address);
|
||||
} else {
|
||||
// rendererTemplates are provided via layout
|
||||
rendererTemplate = address.getType() != undefined && this.rendererTemplates[address.getType()] != undefined ? //eslint-disable-line
|
||||
utils.extend({}, defaultRendererTemplate, this.rendererTemplates[address.getType()]) :
|
||||
defaultRendererTemplate;
|
||||
templateData = {
|
||||
parentName: this.name,
|
||||
name: index
|
||||
};
|
||||
rendererComponent = utils.template(rendererTemplate, templateData);
|
||||
utils.extend(rendererComponent, {
|
||||
address: ko.observable(address)
|
||||
});
|
||||
layout([rendererComponent]);
|
||||
this.rendererComponents[index] = rendererComponent;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/model/step-navigator',
|
||||
'Magento_Checkout/js/model/sidebar'
|
||||
], function ($, Component, quote, stepNavigator, sidebarModel) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/shipping-information'
|
||||
},
|
||||
customerNote: quote.quoteData.customer_note,
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isVisible: function () {
|
||||
return !quote.isVirtual() && stepNavigator.isProcessed('shipping');
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
*/
|
||||
getShippingMethodTitle: function () {
|
||||
var shippingMethod = quote.shippingMethod(),
|
||||
shippingMethodTitle = '';
|
||||
|
||||
if (!shippingMethod) {
|
||||
return '';
|
||||
}
|
||||
|
||||
shippingMethodTitle = shippingMethod['carrier_title'];
|
||||
|
||||
if (typeof shippingMethod['method_title'] !== 'undefined') {
|
||||
shippingMethodTitle += ' - ' + shippingMethod['method_title'];
|
||||
}
|
||||
|
||||
return shippingMethodTitle;
|
||||
},
|
||||
|
||||
/**
|
||||
* Back step.
|
||||
*/
|
||||
back: function () {
|
||||
sidebarModel.hide();
|
||||
stepNavigator.navigateTo('shipping');
|
||||
},
|
||||
|
||||
/**
|
||||
* Back to shipping method.
|
||||
*/
|
||||
backToShippingMethod: function () {
|
||||
sidebarModel.hide();
|
||||
stepNavigator.navigateTo('shipping', 'opc-shipping_method');
|
||||
}
|
||||
});
|
||||
});
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'uiComponent',
|
||||
'underscore',
|
||||
'Magento_Customer/js/customer-data'
|
||||
], function (Component, _, customerData) {
|
||||
'use strict';
|
||||
|
||||
var countryData = customerData.get('directory-data');
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/shipping-information/address-renderer/default'
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {*} countryId
|
||||
* @return {String}
|
||||
*/
|
||||
getCountryName: function (countryId) {
|
||||
return countryData()[countryId] != undefined ? countryData()[countryId].name : ''; //eslint-disable-line
|
||||
},
|
||||
|
||||
/**
|
||||
* Get customer attribute label
|
||||
*
|
||||
* @param {*} attribute
|
||||
* @returns {*}
|
||||
*/
|
||||
getCustomAttributeLabel: function (attribute) {
|
||||
var label;
|
||||
|
||||
if (typeof attribute === 'string') {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
if (attribute.label) {
|
||||
return attribute.label;
|
||||
}
|
||||
|
||||
if (_.isArray(attribute.value)) {
|
||||
label = _.map(attribute.value, function (value) {
|
||||
return this.getCustomAttributeOptionLabel(attribute['attribute_code'], value) || value;
|
||||
}, this).join(', ');
|
||||
} else if (typeof attribute.value === 'object') {
|
||||
label = _.map(Object.values(attribute.value)).join(', ');
|
||||
} else {
|
||||
label = this.getCustomAttributeOptionLabel(attribute['attribute_code'], attribute.value);
|
||||
}
|
||||
|
||||
return label || attribute.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get option label for given attribute code and option ID
|
||||
*
|
||||
* @param {String} attributeCode
|
||||
* @param {String} value
|
||||
* @returns {String|null}
|
||||
*/
|
||||
getCustomAttributeOptionLabel: function (attributeCode, value) {
|
||||
var option,
|
||||
label,
|
||||
options = this.source.get('customAttributes') || {};
|
||||
|
||||
if (options[attributeCode]) {
|
||||
option = _.findWhere(options[attributeCode], {
|
||||
value: value
|
||||
});
|
||||
|
||||
if (option) {
|
||||
label = option.label;
|
||||
}
|
||||
} else if (value.file !== null) {
|
||||
label = value.file;
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
});
|
||||
});
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'ko',
|
||||
'mageUtils',
|
||||
'uiComponent',
|
||||
'uiLayout',
|
||||
'Magento_Checkout/js/model/quote'
|
||||
], function ($, ko, utils, Component, layout, quote) {
|
||||
'use strict';
|
||||
|
||||
var defaultRendererTemplate = {
|
||||
parent: '${ $.$data.parentName }',
|
||||
name: '${ $.$data.name }',
|
||||
component: 'Magento_Checkout/js/view/shipping-information/address-renderer/default',
|
||||
provider: 'checkoutProvider'
|
||||
};
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/shipping-information/list',
|
||||
rendererTemplates: {}
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
initialize: function () {
|
||||
var self = this;
|
||||
|
||||
this._super()
|
||||
.initChildren();
|
||||
|
||||
quote.shippingAddress.subscribe(function (address) {
|
||||
self.createRendererComponent(address);
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
initConfig: function () {
|
||||
this._super();
|
||||
// the list of child components that are responsible for address rendering
|
||||
this.rendererComponents = {};
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/** @inheritdoc */
|
||||
initChildren: function () {
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Create new component that will render given address in the address list
|
||||
*
|
||||
* @param {Object} address
|
||||
*/
|
||||
createRendererComponent: function (address) {
|
||||
var rendererTemplate, templateData, rendererComponent;
|
||||
|
||||
$.each(this.rendererComponents, function (index, component) {
|
||||
component.visible(false);
|
||||
});
|
||||
|
||||
if (this.rendererComponents[address.getType()]) {
|
||||
this.rendererComponents[address.getType()].address(address);
|
||||
this.rendererComponents[address.getType()].visible(true);
|
||||
} else {
|
||||
// rendererTemplates are provided via layout
|
||||
rendererTemplate = address.getType() != undefined && this.rendererTemplates[address.getType()] != undefined ? //eslint-disable-line
|
||||
utils.extend({}, defaultRendererTemplate, this.rendererTemplates[address.getType()]) :
|
||||
defaultRendererTemplate;
|
||||
templateData = {
|
||||
parentName: this.name,
|
||||
name: address.getType()
|
||||
};
|
||||
|
||||
rendererComponent = utils.template(rendererTemplate, templateData);
|
||||
utils.extend(
|
||||
rendererComponent,
|
||||
{
|
||||
address: ko.observable(address),
|
||||
visible: ko.observable(true)
|
||||
}
|
||||
);
|
||||
layout([rendererComponent]);
|
||||
this.rendererComponents[address.getType()] = rendererComponent;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,405 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'Magento_Ui/js/form/form',
|
||||
'ko',
|
||||
'Magento_Customer/js/model/customer',
|
||||
'Magento_Customer/js/model/address-list',
|
||||
'Magento_Checkout/js/model/address-converter',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Checkout/js/action/create-shipping-address',
|
||||
'Magento_Checkout/js/action/select-shipping-address',
|
||||
'Magento_Checkout/js/model/shipping-rates-validator',
|
||||
'Magento_Checkout/js/model/shipping-address/form-popup-state',
|
||||
'Magento_Checkout/js/model/shipping-service',
|
||||
'Magento_Checkout/js/action/select-shipping-method',
|
||||
'Magento_Checkout/js/model/shipping-rate-registry',
|
||||
'Magento_Checkout/js/action/set-shipping-information',
|
||||
'Magento_Checkout/js/model/step-navigator',
|
||||
'Magento_Ui/js/modal/modal',
|
||||
'Magento_Checkout/js/model/checkout-data-resolver',
|
||||
'Magento_Checkout/js/checkout-data',
|
||||
'uiRegistry',
|
||||
'mage/translate',
|
||||
'Magento_Checkout/js/model/shipping-rate-service'
|
||||
], function (
|
||||
$,
|
||||
_,
|
||||
Component,
|
||||
ko,
|
||||
customer,
|
||||
addressList,
|
||||
addressConverter,
|
||||
quote,
|
||||
createShippingAddress,
|
||||
selectShippingAddress,
|
||||
shippingRatesValidator,
|
||||
formPopUpState,
|
||||
shippingService,
|
||||
selectShippingMethodAction,
|
||||
rateRegistry,
|
||||
setShippingInformationAction,
|
||||
stepNavigator,
|
||||
modal,
|
||||
checkoutDataResolver,
|
||||
checkoutData,
|
||||
registry,
|
||||
$t
|
||||
) {
|
||||
'use strict';
|
||||
|
||||
var popUp = null;
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/shipping',
|
||||
shippingFormTemplate: 'Magento_Checkout/shipping-address/form',
|
||||
shippingMethodListTemplate: 'Magento_Checkout/shipping-address/shipping-method-list',
|
||||
shippingMethodItemTemplate: 'Magento_Checkout/shipping-address/shipping-method-item',
|
||||
imports: {
|
||||
countryOptions: '${ $.parentName }.shippingAddress.shipping-address-fieldset.country_id:indexedOptions'
|
||||
}
|
||||
},
|
||||
visible: ko.observable(!quote.isVirtual()),
|
||||
errorValidationMessage: ko.observable(false),
|
||||
isCustomerLoggedIn: customer.isLoggedIn,
|
||||
isFormPopUpVisible: formPopUpState.isVisible,
|
||||
isFormInline: addressList().length === 0,
|
||||
isNewAddressAdded: ko.observable(false),
|
||||
saveInAddressBook: 1,
|
||||
quoteIsVirtual: quote.isVirtual(),
|
||||
customerNote: quote.quoteData.customer_note,
|
||||
|
||||
/**
|
||||
* @return {exports}
|
||||
*/
|
||||
initialize: function () {
|
||||
var self = this,
|
||||
hasNewAddress,
|
||||
fieldsetName = 'checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset';
|
||||
|
||||
this._super();
|
||||
|
||||
if (!quote.isVirtual()) {
|
||||
stepNavigator.registerStep(
|
||||
'shipping',
|
||||
'',
|
||||
$t('Shipping'),
|
||||
this.visible, _.bind(this.navigate, this),
|
||||
this.sortOrder
|
||||
);
|
||||
}
|
||||
checkoutDataResolver.resolveShippingAddress();
|
||||
|
||||
hasNewAddress = addressList.some(function (address) {
|
||||
return address.getType() == 'new-customer-address'; //eslint-disable-line eqeqeq
|
||||
});
|
||||
|
||||
this.isNewAddressAdded(hasNewAddress);
|
||||
|
||||
this.isFormPopUpVisible.subscribe(function (value) {
|
||||
if (value) {
|
||||
self.getPopUp().openModal();
|
||||
}
|
||||
});
|
||||
|
||||
quote.shippingMethod.subscribe(function () {
|
||||
self.errorValidationMessage(false);
|
||||
});
|
||||
|
||||
registry.async('checkoutProvider')(function (checkoutProvider) {
|
||||
var shippingAddressData = checkoutData.getShippingAddressFromData();
|
||||
|
||||
if (shippingAddressData) {
|
||||
checkoutProvider.set(
|
||||
'shippingAddress',
|
||||
$.extend(true, {}, checkoutProvider.get('shippingAddress'), shippingAddressData)
|
||||
);
|
||||
}
|
||||
checkoutProvider.on('shippingAddress', function (shippingAddrsData, changes) {
|
||||
var isStreetAddressDeleted, isStreetAddressNotEmpty;
|
||||
|
||||
/**
|
||||
* In last modifying operation street address was deleted.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
isStreetAddressDeleted = function () {
|
||||
var change;
|
||||
|
||||
if (!changes || changes.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
change = changes.pop();
|
||||
|
||||
if (_.isUndefined(change.value) || _.isUndefined(change.oldValue)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!change.path.startsWith('shippingAddress.street')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return change.value.length === 0 && change.oldValue.length > 0;
|
||||
};
|
||||
|
||||
isStreetAddressNotEmpty = shippingAddrsData.street && !_.isEmpty(shippingAddrsData.street[0]);
|
||||
|
||||
if (isStreetAddressNotEmpty || isStreetAddressDeleted()) {
|
||||
checkoutData.setShippingAddressFromData(shippingAddrsData);
|
||||
}
|
||||
});
|
||||
shippingRatesValidator.initFields(fieldsetName);
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Navigator change hash handler.
|
||||
*
|
||||
* @param {Object} step - navigation step
|
||||
*/
|
||||
navigate: function (step) {
|
||||
step && step.isVisible(true);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getPopUp: function () {
|
||||
var self = this,
|
||||
buttons;
|
||||
|
||||
if (!popUp) {
|
||||
buttons = this.popUpForm.options.buttons;
|
||||
this.popUpForm.options.buttons = [
|
||||
{
|
||||
text: buttons.save.text ? buttons.save.text : $t('Save Address'),
|
||||
class: buttons.save.class ? buttons.save.class : 'action primary action-save-address',
|
||||
click: self.saveNewAddress.bind(self)
|
||||
},
|
||||
{
|
||||
text: buttons.cancel.text ? buttons.cancel.text : $t('Cancel'),
|
||||
class: buttons.cancel.class ? buttons.cancel.class : 'action secondary action-hide-popup',
|
||||
|
||||
/** @inheritdoc */
|
||||
click: this.onClosePopUp.bind(this)
|
||||
}
|
||||
];
|
||||
|
||||
/** @inheritdoc */
|
||||
this.popUpForm.options.closed = function () {
|
||||
self.isFormPopUpVisible(false);
|
||||
};
|
||||
|
||||
this.popUpForm.options.modalCloseBtnHandler = this.onClosePopUp.bind(this);
|
||||
this.popUpForm.options.keyEventHandlers = {
|
||||
escapeKey: this.onClosePopUp.bind(this)
|
||||
};
|
||||
|
||||
/** @inheritdoc */
|
||||
this.popUpForm.options.opened = function () {
|
||||
// Store temporary address for revert action in case when user click cancel action
|
||||
self.temporaryAddress = $.extend(true, {}, checkoutData.getShippingAddressFromData());
|
||||
};
|
||||
popUp = modal(this.popUpForm.options, $(this.popUpForm.element));
|
||||
}
|
||||
|
||||
return popUp;
|
||||
},
|
||||
|
||||
/**
|
||||
* Revert address and close modal.
|
||||
*/
|
||||
onClosePopUp: function () {
|
||||
checkoutData.setShippingAddressFromData($.extend(true, {}, this.temporaryAddress));
|
||||
this.getPopUp().closeModal();
|
||||
},
|
||||
|
||||
/**
|
||||
* Show address form popup
|
||||
*/
|
||||
showFormPopUp: function () {
|
||||
this.isFormPopUpVisible(true);
|
||||
},
|
||||
|
||||
/**
|
||||
* Save new shipping address
|
||||
*/
|
||||
saveNewAddress: function () {
|
||||
var addressData,
|
||||
newShippingAddress;
|
||||
|
||||
this.source.set('params.invalid', false);
|
||||
this.triggerShippingDataValidateEvent();
|
||||
|
||||
if (!this.source.get('params.invalid')) {
|
||||
addressData = this.source.get('shippingAddress');
|
||||
// if user clicked the checkbox, its value is true or false. Need to convert.
|
||||
addressData['save_in_address_book'] = this.saveInAddressBook ? 1 : 0;
|
||||
|
||||
// New address must be selected as a shipping address
|
||||
newShippingAddress = createShippingAddress(addressData);
|
||||
selectShippingAddress(newShippingAddress);
|
||||
checkoutData.setSelectedShippingAddress(newShippingAddress.getKey());
|
||||
checkoutData.setNewCustomerShippingAddress($.extend(true, {}, addressData));
|
||||
this.getPopUp().closeModal();
|
||||
this.isNewAddressAdded(true);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Shipping Method View
|
||||
*/
|
||||
rates: shippingService.getShippingRates(),
|
||||
isLoading: shippingService.isLoading,
|
||||
isSelected: ko.computed(function () {
|
||||
return quote.shippingMethod() ?
|
||||
quote.shippingMethod()['carrier_code'] + '_' + quote.shippingMethod()['method_code'] :
|
||||
null;
|
||||
}),
|
||||
|
||||
/**
|
||||
* @param {Object} shippingMethod
|
||||
* @return {Boolean}
|
||||
*/
|
||||
selectShippingMethod: function (shippingMethod) {
|
||||
selectShippingMethodAction(shippingMethod);
|
||||
checkoutData.setSelectedShippingRate(shippingMethod['carrier_code'] + '_' + shippingMethod['method_code']);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set shipping information handler
|
||||
*/
|
||||
setShippingInformation: function () {
|
||||
if (this.validateShippingInformation()) {
|
||||
quote.billingAddress(null);
|
||||
checkoutDataResolver.resolveBillingAddress();
|
||||
registry.async('checkoutProvider')(function (checkoutProvider) {
|
||||
var shippingAddressData = checkoutData.getShippingAddressFromData();
|
||||
|
||||
if (shippingAddressData) {
|
||||
checkoutProvider.set(
|
||||
'shippingAddress',
|
||||
$.extend(true, {}, checkoutProvider.get('shippingAddress'), shippingAddressData)
|
||||
);
|
||||
}
|
||||
});
|
||||
setShippingInformationAction().done(
|
||||
function () {
|
||||
stepNavigator.next();
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
validateShippingInformation: function () {
|
||||
var shippingAddress,
|
||||
addressData,
|
||||
loginFormSelector = 'form[data-role=email-with-possible-login]',
|
||||
emailValidationResult = customer.isLoggedIn(),
|
||||
field,
|
||||
option = _.isObject(this.countryOptions) && this.countryOptions[quote.shippingAddress().countryId],
|
||||
messageContainer = registry.get('checkout.errors').messageContainer;
|
||||
|
||||
if (!quote.shippingMethod()) {
|
||||
this.errorValidationMessage(
|
||||
$t('The shipping method is missing. Select the shipping method and try again.')
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!customer.isLoggedIn()) {
|
||||
$(loginFormSelector).validation();
|
||||
emailValidationResult = Boolean($(loginFormSelector + ' input[name=username]').valid());
|
||||
}
|
||||
|
||||
if (this.isFormInline) {
|
||||
this.source.set('params.invalid', false);
|
||||
this.triggerShippingDataValidateEvent();
|
||||
|
||||
if (!quote.shippingMethod()['method_code']) {
|
||||
this.errorValidationMessage(
|
||||
$t('The shipping method is missing. Select the shipping method and try again.')
|
||||
);
|
||||
}
|
||||
|
||||
if (emailValidationResult &&
|
||||
this.source.get('params.invalid') ||
|
||||
!quote.shippingMethod()['method_code'] ||
|
||||
!quote.shippingMethod()['carrier_code']
|
||||
) {
|
||||
this.focusInvalid();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
shippingAddress = quote.shippingAddress();
|
||||
addressData = addressConverter.formAddressDataToQuoteAddress(
|
||||
this.source.get('shippingAddress')
|
||||
);
|
||||
|
||||
//Copy form data to quote shipping address object
|
||||
for (field in addressData) {
|
||||
if (addressData.hasOwnProperty(field) && //eslint-disable-line max-depth
|
||||
shippingAddress.hasOwnProperty(field) &&
|
||||
typeof addressData[field] != 'function' &&
|
||||
_.isEqual(shippingAddress[field], addressData[field])
|
||||
) {
|
||||
shippingAddress[field] = addressData[field];
|
||||
} else if (typeof addressData[field] != 'function' &&
|
||||
!_.isEqual(shippingAddress[field], addressData[field])) {
|
||||
shippingAddress = addressData;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (customer.isLoggedIn()) {
|
||||
shippingAddress['save_in_address_book'] = 1;
|
||||
}
|
||||
selectShippingAddress(shippingAddress);
|
||||
} else if (customer.isLoggedIn() &&
|
||||
option &&
|
||||
option['is_region_required'] &&
|
||||
!quote.shippingAddress().region
|
||||
) {
|
||||
messageContainer.addErrorMessage({
|
||||
message: $t('Please specify a regionId in shipping address.')
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!emailValidationResult) {
|
||||
$(loginFormSelector + ' input[name=username]').trigger('focus');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Trigger Shipping data Validate Event.
|
||||
*/
|
||||
triggerShippingDataValidateEvent: function () {
|
||||
this.source.trigger('shippingAddress.data.validate');
|
||||
|
||||
if (this.source.get('shippingAddress.custom_attributes')) {
|
||||
this.source.trigger('shippingAddress.custom_attributes.data.validate');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'uiComponent',
|
||||
'ko',
|
||||
'jquery',
|
||||
'Magento_Checkout/js/model/sidebar'
|
||||
], function (Component, ko, $, sidebarModel) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
/**
|
||||
* @param {HTMLElement} element
|
||||
*/
|
||||
setModalElement: function (element) {
|
||||
sidebarModel.setPopup($(element));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/totals',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
], function (Component, totals, quote) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
isLoading: totals.isLoading,
|
||||
quoteData: quote.quoteData
|
||||
});
|
||||
});
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Catalog/js/price-utils',
|
||||
'Magento_Checkout/js/model/totals',
|
||||
'Magento_Checkout/js/model/step-navigator'
|
||||
], function (Component, quote, priceUtils, totals, stepNavigator) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
/**
|
||||
* @param {*} price
|
||||
* @return {*|String}
|
||||
*/
|
||||
getFormattedPrice: function (price) {
|
||||
return priceUtils.formatPriceLocale(price, quote.getPriceFormat());
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
getTotals: function () {
|
||||
return totals.totals();
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
isFullMode: function () {
|
||||
if (!this.getTotals()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return stepNavigator.isProcessed('shipping');
|
||||
}
|
||||
});
|
||||
});
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'ko',
|
||||
'Magento_Checkout/js/model/totals',
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/step-navigator',
|
||||
'Magento_Checkout/js/model/quote'
|
||||
], function (ko, totals, Component, stepNavigator, quote) {
|
||||
'use strict';
|
||||
|
||||
var useQty = window.checkoutConfig.useQty;
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/summary/cart-items'
|
||||
},
|
||||
totals: totals.totals(),
|
||||
items: ko.observable([]),
|
||||
maxCartItemsToDisplay: window.checkoutConfig.maxCartItemsToDisplay,
|
||||
cartUrl: window.checkoutConfig.cartUrl,
|
||||
|
||||
/**
|
||||
* @deprecated Please use observable property (this.items())
|
||||
*/
|
||||
getItems: totals.getItems(),
|
||||
|
||||
/**
|
||||
* Returns cart items qty
|
||||
*
|
||||
* @returns {Number}
|
||||
*/
|
||||
getItemsQty: function () {
|
||||
return parseFloat(this.totals['items_qty']);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns count of cart line items
|
||||
*
|
||||
* @returns {Number}
|
||||
*/
|
||||
getCartLineItemsCount: function () {
|
||||
return parseInt(totals.getItems()().length, 10);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns shopping cart items summary (includes config settings)
|
||||
*
|
||||
* @returns {Number}
|
||||
*/
|
||||
getCartSummaryItemsCount: function () {
|
||||
return useQty ? this.getItemsQty() : this.getCartLineItemsCount();
|
||||
},
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
initialize: function () {
|
||||
this._super();
|
||||
// Set initial items to observable field
|
||||
this.setItems(totals.getItems()());
|
||||
// Subscribe for items data changes and refresh items in view
|
||||
totals.getItems().subscribe(function (items) {
|
||||
this.setItems(items);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Set items to observable field
|
||||
*
|
||||
* @param {Object} items
|
||||
*/
|
||||
setItems: function (items) {
|
||||
if (items && items.length > 0) {
|
||||
items = items.slice(parseInt(-this.maxCartItemsToDisplay, 10));
|
||||
}
|
||||
this.items(items);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns bool value for items block state (expanded or not)
|
||||
*
|
||||
* @returns {*|Boolean}
|
||||
*/
|
||||
isItemsBlockExpanded: function () {
|
||||
return quote.isVirtual() || stepNavigator.isProcessed('shipping');
|
||||
}
|
||||
});
|
||||
});
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'Magento_Checkout/js/view/summary/abstract-total',
|
||||
'Magento_Checkout/js/model/quote'
|
||||
], function (Component, quote) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/summary/grand-total'
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*}
|
||||
*/
|
||||
isDisplayed: function () {
|
||||
return this.isFullMode();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get pure value.
|
||||
*/
|
||||
getPureValue: function () {
|
||||
var totals = quote.getTotals()();
|
||||
|
||||
if (totals) {
|
||||
return totals['grand_total'];
|
||||
}
|
||||
|
||||
return quote['grand_total'];
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {*|String}
|
||||
*/
|
||||
getValue: function () {
|
||||
return this.getFormattedPrice(this.getPureValue());
|
||||
}
|
||||
});
|
||||
});
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'uiComponent',
|
||||
'escaper',
|
||||
'Magento_Checkout/js/model/quote',
|
||||
'Magento_Catalog/js/price-utils'
|
||||
], function (Component, escaper, quote, priceUtils) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/summary/item/details',
|
||||
allowedTags: ['b', 'strong', 'i', 'em', 'u']
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} quoteItem
|
||||
* @return {String}
|
||||
*/
|
||||
getNameUnsanitizedHtml: function (quoteItem) {
|
||||
|
||||
var txt = document.createElement('textarea');
|
||||
|
||||
txt.innerHTML = quoteItem.name;
|
||||
|
||||
return escaper.escapeHtml(txt.value, this.allowedTags);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} quoteItem
|
||||
* @return {String}Magento_Checkout/js/region-updater
|
||||
*/
|
||||
getValue: function (quoteItem) {
|
||||
return quoteItem.name;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} quoteItem
|
||||
* @return {String}
|
||||
*/
|
||||
getBookingAccount: function (quoteItem) {
|
||||
return quoteItem.lab_booking_account;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} quoteItem
|
||||
* @return {String}
|
||||
*/
|
||||
getProductPrice: function (quoteItem) {
|
||||
return priceUtils.formatPriceLocale(quoteItem.price, quote.getPriceFormat());
|
||||
}
|
||||
});
|
||||
});
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define(['uiComponent'], function (Component) {
|
||||
'use strict';
|
||||
|
||||
var quoteMessages = window.checkoutConfig.quoteMessages;
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/summary/item/details/message'
|
||||
},
|
||||
displayArea: 'item_message',
|
||||
quoteMessages: quoteMessages,
|
||||
|
||||
/**
|
||||
* @param {Object} item
|
||||
* @return {null}
|
||||
*/
|
||||
getMessage: function (item) {
|
||||
if (this.quoteMessages[item['item_id']]) {
|
||||
return this.quoteMessages[item['item_id']];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
});
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define([
|
||||
'Magento_Checkout/js/view/summary/abstract-total'
|
||||
], function (viewModel) {
|
||||
'use strict';
|
||||
|
||||
return viewModel.extend({
|
||||
defaults: {
|
||||
displayArea: 'after_details',
|
||||
template: 'Magento_Checkout/summary/item/details/subtotal'
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} quoteItem
|
||||
* @return {*|String}
|
||||
*/
|
||||
getValue: function (quoteItem) {
|
||||
return this.getFormattedPrice(quoteItem['row_total']);
|
||||
}
|
||||
});
|
||||
});
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
define(['uiComponent'], function (Component) {
|
||||
'use strict';
|
||||
|
||||
var imageData = window.checkoutConfig.imageData;
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Magento_Checkout/summary/item/details/thumbnail'
|
||||
},
|
||||
displayArea: 'before_details',
|
||||
imageData: imageData,
|
||||
|
||||
/**
|
||||
* @param {Object} item
|
||||
* @return {Array}
|
||||
*/
|
||||
getImageItem: function (item) {
|
||||
if (this.imageData[item['item_id']]) {
|
||||
return this.imageData[item['item_id']];
|
||||
}
|
||||
|
||||
return [];
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} item
|
||||
* @return {null}
|
||||
*/
|
||||
getSrc: function (item) {
|
||||
if (this.imageData[item['item_id']]) {
|
||||
return this.imageData[item['item_id']].src;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} item
|
||||
* @return {null}
|
||||
*/
|
||||
getWidth: function (item) {
|
||||
if (this.imageData[item['item_id']]) {
|
||||
return this.imageData[item['item_id']].width;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} item
|
||||
* @return {null}
|
||||
*/
|
||||
getHeight: function (item) {
|
||||
if (this.imageData[item['item_id']]) {
|
||||
return this.imageData[item['item_id']].height;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} item
|
||||
* @return {null}
|
||||
*/
|
||||
getAlt: function (item) {
|
||||
if (this.imageData[item['item_id']]) {
|
||||
return this.imageData[item['item_id']].alt;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user