0

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);
        }
    });
});

2 Answers 2

0

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
0

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

3
  • Inside getConvertedTotal function unable to get value it is undefined, however inside initialize: function(config) I am able to get data using console.log
    – ishaq
    Commented Feb 5, 2021 at 5:07
  • 1
    I really hope you spend your time to learn some basic about javascript, this will save you alot of time when learning Magento or any other framework/library
    – Jimmy
    Commented Feb 5, 2021 at 7:37
  • 1
    @ishaq That is because your currencySymbol variable is only available within the initialize function. You need to change it to this.currencyRate = config.currencyRate
    – Ben Crook
    Commented Feb 5, 2021 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.