0

In my custom module, I need to Display subtotal without discount(subtotal - discount) how can I achieve my needs? , any help appreciated.
Thank you

1

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.

  • @shafeel-sha are you getting any issues ? – Kishan Savaliya Oct 15 at 13:46
  • yes , not getting correct value , subtotal added with discount – Shafeel Sha Oct 15 at 13:55
  • 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 ? – Kishan Savaliya Oct 15 at 13:59
  • After adding above code please clear your browser cache once and then try to check. that will work. – Kishan Savaliya Oct 15 at 13:59
  • Thanks Brother its working now – Shafeel Sha Oct 17 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.