I want to apply multiple discount in separate line.Right now i have coupn code and sales rule applied in same cart what should i do so cart and checkout page display relevant discount in separate line in magento2.


1 Answer 1


1) Create checkout_cart_index

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceContainer name="content"> 
        <block class="Ktpl\Extrafee\Block\Discounts" name="block.banner" as="block.custom.cms" template="Vendor_Module::discounts.phtml" before="-" />
            <referenceBlock name="checkout.cart.totals">
                    <argument name="jsLayout" xsi:type="array">
                        <item name="components" xsi:type="array">
                            <item name="block-totals" xsi:type="array">
                                <item name="children" xsi:type="array">
                                    <item name="before_grandtotal" xsi:type="array">
                                        <item name="children" xsi:type="array">
                                            <item name="fee" xsi:type="array">
                                                <item name="component" xsi:type="string">Vendor_Module/js/view/checkout/cart/totals/fee</item>
                                                <item name="sortOrder" xsi:type="string">20</item>
                                                <item name="config" xsi:type="array">
                                                    <item name="template" xsi:type="string">Vendor_Module/checkout/cart/totals/fee</item>
                                                    <!-- <item name="title" xsi:type="helper" translate="true" helper="Ktpl\Extrafee\Helper\Data::getTitle"/> -->

2) Now create fee.js at


    function (Component) {
        'use strict';

        return Component.extend({

             * @override
            isDisplayed: function () {
                return true;

            discounts: function() { 

                var alldiscount = window.discounts;

                return alldiscount;



3) Create fee.html at


<!-- ko -->

        <table data-bind="foreach: discounts()">
            <tr class="totals fee excl" >
            <th class="mark" colspan="1" scope="row" data-bind="text: title"></th>
            <td class="amount">
                <span class="price" data-bind="text: amount"></span>

<!-- /ko -->

4) Now create discounts and pass your array of discount



$totalDiscounts = $block->getAllDiscounts();

/* Your array should look like this
$discounts = [
                 ['title' => 'First Discount', 'amount' => '-10' ],
                 [ 'title' => 'Second Discount', 'amount' => '-5' ]
             ]; */
    window.discounts = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($totalDiscounts) ?>;
  • 2
    How we get the discount amount from quite based on rule id? Mar 2, 2019 at 6:40

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.