0

In my case my demand is to display the weight for the product also like the name, the quantity ..., in the mini cart but I can't find a proper way to display the weight, can anyone tell me how please :

this is the code that is responsible for displaying data in the cart

File location :

vendor/magento/module-checkout/view/frontend/web/template/minicart/item/default.html

The code :

<div class="product options" data-mage-init='{"collapsible":{"openedState": "active", "saveState": false}}'>
                <span data-role="title" class="toggle"><!-- ko i18n: 'See Details' --><!-- /ko --></span>

                <div data-role="content" class="content">
                    <strong class="subtitle"><!-- ko i18n: 'Options Details' --><!-- /ko --></strong>
                    <dl class="product options list">
                        <!-- ko foreach: { data: options, as: 'option' } -->
                        <dt class="label"><!-- ko text: option.label --><!-- /ko --></dt>
                        <dd class="values">
                            <!-- ko if: Array.isArray(option.value) -->
                                <span data-bind="html: option.value.join('<br>')"></span>
                            <!-- /ko -->
                            <!-- ko ifnot: Array.isArray(option.value) -->
                                <span data-bind="html: option.value"></span>
                            <!-- /ko -->
                        </dd>
                        <!-- /ko -->
                        <strong class="product-item-name">
                            <!-- ko if: product_has_url -->
                            <a data-bind="attr: {href: product_url}, html: product_name"></a>
                            <!-- /ko -->
                            <!-- ko ifnot: product_has_url -->
                            <!-- ko text: product_name --><!-- /ko -->
                            <!-- /ko -->
                        </strong>
                    </dl>
                </div>
            </div>
1

1 Answer 1

1

For that, You need to add one custom function and pass your precision value and weight value. Add this below code in your html file :

<strong class="product-item-Weight">
<!-- ko if: weight -->
    <div class="Approx-Weight" data-bind="html: 'Approx Weight : ' + getWeight(2,weight * qty) ">
    </div>
<!-- /ko -->
</strong>

Now, create getWeight() function in your knockout file inside Component.extend :

getWeight : function(precision,WeightValue){
    var self = this;
    return WeightValue / Math.pow(10, self.precision());
},

Now, refresh your html and knockout js file and check it.

And More refer this :-

How to get decimal value of weight in mini cart?

Thanks...

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.