Magento 2: Show subtotal without discount in Cart page
문제
In my custom module, I need to Display subtotal without discount(subtotal - discount)
how can I achieve my needs? , any help appreciated.
Thank you
해결책
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.