In my custom module, I need to Display subtotal without discount(subtotal - discount)
how can I achieve my needs? , any help appreciated.
Thank you
-
Where you want to display that subtotal in your custom module?– Kishan SavaliyaOct 15, 2019 at 11:13
-
in my summery section– Shafeel ShaOct 15, 2019 at 11:14
-
In Magento, Order edit page in backend or frontend ?– Kishan SavaliyaOct 15, 2019 at 11:15
-
in frontend , user cart (summery block below the discount)– Shafeel ShaOct 15, 2019 at 11:16
-
You mean you want to change subtotal here ? drive.google.com/file/d/1jqTlHoc-PH5M_bCiBqDBSEK9HjJNZsH4/…– Kishan SavaliyaOct 15, 2019 at 11:32
1 Answer
You can override getValue() function in this js in your module
vendor/magento/module-tax/view/frontend/web/js/view/checkout/summary/subtotal.js
In your custom module you can override that function as below...
app/code/MageHelper/ShippingDiscount/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'MageHelper_ShippingDiscount',
__DIR__
);
app/code/MageHelper/ShippingDiscount/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MageHelper_ShippingDiscount" setup_version="1.0.0" />
</config>
app/code/MageHelper/ShippingDiscount/view/frontend/requirejs-config.js
var config = {
config: {
mixins: {
'Magento_Tax/js/view/checkout/summary/subtotal': {
'MageHelper_ShippingDiscount/js/view/checkout/summary/subtotal-mixin': true
}
}
}
};
app/code/MageHelper/ShippingDiscount/view/frontend/web/js/view/checkout/summary/subtotal-mixin.js
define([
'Magento_Checkout/js/view/summary/abstract-total',
'Magento_Checkout/js/model/quote'
], function (Component, quote) {
'use strict';
var mixin = {
getValue: function () {
var price = 0;
if (this.totals()) {
price = this.totals().subtotal + this.totals().base_discount_amount;
}
return this.getFormattedPrice(price);
}
};
return function (target) {
return target.extend(mixin);
};
});
You can add your vendor and module name where I've added MageHelper and ShippingDiscount
Hope this will work for you.
-
-
-
I've added this this.totals().subtotal + this.totals().base_discount_amount because in base_discount_amount we will get amount with minus (-) sign. What exact issue you are getting there ? Oct 15, 2019 at 13:59
-
After adding above code please clear your browser cache once and then try to check. that will work. Oct 15, 2019 at 13:59
-