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?
2 Answers
getValue() in js file formats the amount to two decimal places and also adds the current currency symbol. It was necessary to modify it.
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;
}
});
}
);