Skip to main content
Tweeted twitter.com/StackMagento/status/1321013790255783937
Became Hot Network Question
added 11 characters in body
Source Link
Black
  • 3.4k
  • 4
  • 40
  • 123

I try to understand knockoutjs and requirejs more but I fail to understand the following case.

In checkout the shipping method title is showing in the summary

enter image description here

This is the template:

vendor/magento/module-tax/view/frontend/web/template/checkout/summary/shipping.html

...
<span class="value" data-bind="text: getShippingMethodTitle()"></span>
...

The method getShippingMethodTitle() seems to be defined here:

vendor/magento/module-tax/view/frontend/web/js/view/checkout/cart/totals/shipping.js (Script A)

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @api
 */

define([
    'Magento_Tax/js/view/checkout/summary/shipping',
    'Magento_Checkout/js/model/quote'
], function (Component, quote) {
    'use strict';

    return Component.extend({
        /**
         * @override
         */
        isCalculated: function () {
            return !!quote.shippingMethod();
        },

        /**
         * @override
         */
        getShippingMethodTitle: function () {
            return '(' + this._super() + ')';
        }
    });
});

It just returns this._super() so it means it tries to access the parent method _super, but where is the parent? I think Component is the parent, but there is no method called _super in 'Magento_Tax/js/view/checkout/summary/shipping'

So how does it know the method name?

I try to understand knockoutjs and requirejs more but I fail to understand the following case.

In checkout the shipping method title is showing in the summary

enter image description here

This is the template:

vendor/magento/module-tax/view/frontend/web/template/checkout/summary/shipping.html

...
<span class="value" data-bind="text: getShippingMethodTitle()"></span>
...

The method getShippingMethodTitle() seems to be defined here:

vendor/magento/module-tax/view/frontend/web/js/view/checkout/cart/totals/shipping.js

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @api
 */

define([
    'Magento_Tax/js/view/checkout/summary/shipping',
    'Magento_Checkout/js/model/quote'
], function (Component, quote) {
    'use strict';

    return Component.extend({
        /**
         * @override
         */
        isCalculated: function () {
            return !!quote.shippingMethod();
        },

        /**
         * @override
         */
        getShippingMethodTitle: function () {
            return '(' + this._super() + ')';
        }
    });
});

It just returns this._super() so it means it tries to access the parent method _super, but where is the parent? I think Component is the parent, but there is no method called _super in 'Magento_Tax/js/view/checkout/summary/shipping'

So how does it know the method name?

I try to understand knockoutjs and requirejs more but I fail to understand the following case.

In checkout the shipping method title is showing in the summary

enter image description here

This is the template:

vendor/magento/module-tax/view/frontend/web/template/checkout/summary/shipping.html

...
<span class="value" data-bind="text: getShippingMethodTitle()"></span>
...

The method getShippingMethodTitle() seems to be defined here:

vendor/magento/module-tax/view/frontend/web/js/view/checkout/cart/totals/shipping.js (Script A)

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @api
 */

define([
    'Magento_Tax/js/view/checkout/summary/shipping',
    'Magento_Checkout/js/model/quote'
], function (Component, quote) {
    'use strict';

    return Component.extend({
        /**
         * @override
         */
        isCalculated: function () {
            return !!quote.shippingMethod();
        },

        /**
         * @override
         */
        getShippingMethodTitle: function () {
            return '(' + this._super() + ')';
        }
    });
});

It just returns this._super() so it means it tries to access the parent method _super, but where is the parent? I think Component is the parent, but there is no method called _super in 'Magento_Tax/js/view/checkout/summary/shipping'

So how does it know the method name?

added 9 characters in body
Source Link
Black
  • 3.4k
  • 4
  • 40
  • 123

I try to understand knockoutjs and requirejs more but I fail to understand the following case.

In checkout the shipping method title is showing in the summary

enter image description here

This is the template:

vendor/magento/module-tax/view/frontend/web/template/checkout/summary/shipping.html

...
<span class="value" data-bind="text: getShippingMethodTitle()"></span>
...

The method getShippingMethodTitle() isseems to be defined here:

vendor/magento/module-tax/view/frontend/web/js/view/checkout/cart/totals/shipping.js

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @api
 */

define([
    'Magento_Tax/js/view/checkout/summary/shipping',
    'Magento_Checkout/js/model/quote'
], function (Component, quote) {
    'use strict';

    return Component.extend({
        /**
         * @override
         */
        isCalculated: function () {
            return !!quote.shippingMethod();
        },

        /**
         * @override
         */
        getShippingMethodTitle: function () {
            return '(' + this._super() + ')';
        }
    });
});

It just returns this._super() so it means it tries to access the parent method _super, but where is the parent? I think Component is the parent, but there is no method called _super in 'Magento_Tax/js/view/checkout/summary/shipping'

So how does it know the method name?

I try to understand knockoutjs and requirejs more but I fail to understand the following case.

In checkout the shipping method title is showing in the summary

enter image description here

This is the template:

vendor/magento/module-tax/view/frontend/web/template/checkout/summary/shipping.html

...
<span class="value" data-bind="text: getShippingMethodTitle()"></span>
...

The method getShippingMethodTitle() is defined here:

vendor/magento/module-tax/view/frontend/web/js/view/checkout/cart/totals/shipping.js

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @api
 */

define([
    'Magento_Tax/js/view/checkout/summary/shipping',
    'Magento_Checkout/js/model/quote'
], function (Component, quote) {
    'use strict';

    return Component.extend({
        /**
         * @override
         */
        isCalculated: function () {
            return !!quote.shippingMethod();
        },

        /**
         * @override
         */
        getShippingMethodTitle: function () {
            return '(' + this._super() + ')';
        }
    });
});

It just returns this._super() so it means it tries to access the parent method _super, but where is the parent? I think Component is the parent, but there is no method called _super in 'Magento_Tax/js/view/checkout/summary/shipping'

So how does it know the method name?

I try to understand knockoutjs and requirejs more but I fail to understand the following case.

In checkout the shipping method title is showing in the summary

enter image description here

This is the template:

vendor/magento/module-tax/view/frontend/web/template/checkout/summary/shipping.html

...
<span class="value" data-bind="text: getShippingMethodTitle()"></span>
...

The method getShippingMethodTitle() seems to be defined here:

vendor/magento/module-tax/view/frontend/web/js/view/checkout/cart/totals/shipping.js

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @api
 */

define([
    'Magento_Tax/js/view/checkout/summary/shipping',
    'Magento_Checkout/js/model/quote'
], function (Component, quote) {
    'use strict';

    return Component.extend({
        /**
         * @override
         */
        isCalculated: function () {
            return !!quote.shippingMethod();
        },

        /**
         * @override
         */
        getShippingMethodTitle: function () {
            return '(' + this._super() + ')';
        }
    });
});

It just returns this._super() so it means it tries to access the parent method _super, but where is the parent? I think Component is the parent, but there is no method called _super in 'Magento_Tax/js/view/checkout/summary/shipping'

So how does it know the method name?

Source Link
Black
  • 3.4k
  • 4
  • 40
  • 123

Magento 2 - How does getShippingMethodTitle know the method title in module-tax/view/frontend/web/js/view/checkout/cart/totals/shipping.js

I try to understand knockoutjs and requirejs more but I fail to understand the following case.

In checkout the shipping method title is showing in the summary

enter image description here

This is the template:

vendor/magento/module-tax/view/frontend/web/template/checkout/summary/shipping.html

...
<span class="value" data-bind="text: getShippingMethodTitle()"></span>
...

The method getShippingMethodTitle() is defined here:

vendor/magento/module-tax/view/frontend/web/js/view/checkout/cart/totals/shipping.js

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @api
 */

define([
    'Magento_Tax/js/view/checkout/summary/shipping',
    'Magento_Checkout/js/model/quote'
], function (Component, quote) {
    'use strict';

    return Component.extend({
        /**
         * @override
         */
        isCalculated: function () {
            return !!quote.shippingMethod();
        },

        /**
         * @override
         */
        getShippingMethodTitle: function () {
            return '(' + this._super() + ')';
        }
    });
});

It just returns this._super() so it means it tries to access the parent method _super, but where is the parent? I think Component is the parent, but there is no method called _super in 'Magento_Tax/js/view/checkout/summary/shipping'

So how does it know the method name?