I want to get cart grand total(Summary) without shipping cost in checkout/cart page in Magento2.1.7?
Asked
Active
Viewed 2,072 times
0
-
You can get idea from this https://magento.stackexchange.com/questions/92774/how-to-add-fee-to-order-totals-in-magento-2 – Ajwad Syed Dec 03 '18 at 09:54
1 Answers
-1
KnockOut js requests the Total from the getValue() function in
vendor/magento/module-tax/view/frontend/web/js/view/checkout/summary/grand-total.js.
If you only want to change the Total on Cart, you need to override
vendor/magento/module-tax/view/frontend/web/js/view/checkout/cart/totals/grand-total.js .
This js extends the first one so you can make changes that will only be applicable on the cart. Here's a good example on how to replace a js if you don't already have a custom theme: https://www.scommerce-mage.com/blog/override-core-javascript-files-magento-2.html
Your modified js should look like :
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* @api
*/
define([
'Magento_Tax/js/view/checkout/summary/grand-total',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/totals'
], function (Component, quote, totals) {
'use strict';
return Component.extend({
totals: quote.getTotals(),
/**
* @override
*/
isDisplayed: function () {
return true;
},
/**
* Remove shipping cost from cart Total
* @returns {*|String}
*/
getValue: function () {
var price = 0;
if (this.totals()) {
price = totals.getSegment('grand_total').value - totals.getSegment('shipping').value;
}
return this.getFormattedPrice(price);
}
});
});
This will override the function getValue(), only for the cart.