123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- /**
- * 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';
- }
- };
- }
- );
|