1

Using this tutorial https://www.siphor.com/add-a-custom-total-in-magento-2/ I created a totals for total weight of products. Generally it almost works but the prefix with currency symbol is automaticaly added to my total. I would like to change it to "lbs". How can I do that?enter image description here

2 Answers 2

0

getValue() in js file formats the amount to two decimal places and also adds the current currency symbol. It was necessary to modify it.

0

In the file app/code/[Vendor]/[Module]/view/frontend/web/js/view/checkout/summary/custom_amount.js, change the line return this.getFormattedPrice(price); to return price+' lbs';. The complete codes is below:

// app/code/[Vendor]/[Module]/view/frontend/web/js/view/checkout/summary/custom_amount.js

define(
    [
        'Magento_Checkout/js/view/summary/abstract-total',
        'Magento_Checkout/js/model/quote',
        'Magento_Catalog/js/price-utils',
        'Magento_Checkout/js/model/totals'
    ],
    function (Component, quote, priceUtils, totals) {
        "use strict";
        return Component.extend({
            defaults: {
                isFullTaxSummaryDisplayed: window.checkoutConfig.isFullTaxSummaryDisplayed || false,
                template: '[Vendor]_[Module]/checkout/summary/custom_amount'
            },
            totals: quote.getTotals(),
            isTaxDisplayedInGrandTotal: window.checkoutConfig.includeTaxInGrandTotal || false,

            isDisplayed: function() {
                return this.isFullMode() && this.getPureValue() !== 0;
            },

            getValue: function() {
                var price = 0;
                if (this.totals()) {
                    price = totals.getSegment('custom_amount').value;
                }
                return price+' lbs';
            },
            getPureValue: function() {
                var price = 0;
                if (this.totals()) {
                    price = totals.getSegment('custom_amount').value;
                }
                return price;
            }
        });
    }
);

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.