123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- /**
- * @api
- */
- define([
- 'ko',
- 'underscore'
- ], 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,
- 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;
- }
- };
- });
|