Question

I am using Knockout as a View Model to fill values of my view template, It is working fine for all except one function getConvertedTotal is returning NaN.

define([
'ko',
'uiComponent',
'mage/url',
'mage/storage',
'Magento_Checkout/js/model/quote',
],function (ko, Component, urlBuilder,storage,quote) 
{
    'use strict';
    return Component.extend({
        defaults: {template: 'Ishaq_CheckoutTotal/custom-block-order-summary',},
        initialize: function(config) {
            this._super();
            var currencyRate = config.currencyRate;
            var currencySymbol = config.currencySymbol;
        },
        getSubtotal: function() {
            var totals = quote.totals();
            return (totals ? totals : quote)['subtotal'];
        },
        getGrandTotal: function() {
            var totals = quote.totals();
            return (totals ? totals : quote)['grand_total'] ;            
        },
        getConvertedTotal: function() {
            var totals = quote.totals();
            var temp = (totals ? totals : quote)['grand_total'] ;
            return (temp*this.currencyRate);
        }
    });
});
Was it helpful?

Solution

This means one of your values are not a number, either temp or this.currencyRate. My guess is that this.currencyRate is not returning a number (probably undefined).

In that case you need to change:

var currencyRate = config.currencyRate

to

this.currencyRate = config.currencyRate

OTHER TIPS

It's obvious from the code that this.currencyRate is undefined

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top