0

I want to custom data render from shipping method render. I have changed files(template in this file js):

Magento_Checkout/js/view/cart/shipping-rates.js

getSubfixLabel: function(){

            var label =  window.checkout.estimate_label_subfix;

            return label;
        },

Magento_Checkout/template/shipping-rates.html

<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<form id="co-shipping-method-form" data-bind="blockLoader: isLoading, visible: isVisible()" >
    <p class="field note" data-bind="visible: (!isLoading() && shippingRates().length <= 0)">
        <!-- ko text: $t('Sorry, no quotes are available for this order at this time')--><!-- /ko -->
    </p>
    <fieldset class="fieldset rate" data-bind="visible: (shippingRates().length > 0)">
        <dl class="items methods" data-bind="foreach: shippingRateGroups" >
            <dd class="item-options" data-bind="foreach: { data:$parent.getRatesForGroup($data), as: 'method' }" afterRender="$parent.showEstimateLabelAfterRender">
                <div data-bind="css: {'field choice item': available, 'message error': !available} ">
                    <!-- ko ifnot: (available) -->
                    <div data-bind="text: error_message"></div>
                    <!-- /ko -->
                    <!-- ko if: (available) -->
                    <input type="radio"
                           class="radio"
                           data-bind="
                                click: $parents[1].selectShippingMethod,
                                checked: $parents[1].selectedShippingMethod,
                                attr: {
                                        value: carrier_code + '_' + method_code,
                                        id: 's_method_' + carrier_code + '_' + method_code
                                        }
                                "/>
                    <label class="label" data-bind="attr: {for: 's_method_' + carrier_code + '_' + method_code}">
                        <!-- ko text: $data.method_title --><!-- /ko -->
                        <each args="element.getRegion('price')" render="" />
                        <div data-bind="html: getSubfixLabel"></div>
                    </label>
                    <!-- /ko -->
                    <div class="estimate_shipping no-display" data-bind="attr: {id: 'label_carrier_' + method_code + '_' + carrier_code}">
                        <!-- ko text: $data.carrier_title --><!-- /ko -->
                    </div>
                </div>
            </dd>
        </dl>
    </fieldset>
</form>

I want to get data from function getSubfixLabel and render by html. However, it's showing this function undefined.

ReferenceError: estimate_label_subfix is not defined

Anyone can help me out this issues?

1 Answer 1

0

First you can check this in chrome browser console, enter "window.checkout.estimate_label_subfix" and check if its set in the checkout object.

2
  • it really added. I find the problem, I must call $parent[1].getSubfixLabel() in template file. It will work
    – the light
    Apr 6, 2020 at 7:23
  • Great , if issue solved. Apr 6, 2020 at 7:24

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.