2

I have followed https://webkul.com/blog/set-custom-discount-fee-cart-magento-2/ to get dynamic value. I tried below code.

define(
  [
      'jquery',
       'Magento_Checkout/js/view/summary/abstract-total',
       'Magento_Checkout/js/model/quote',
       'Magento_Catalog/js/price-utils',
       'Magento_Checkout/js/model/totals'
  ],
  function ($,Component, quote, priceUtils, totals) {
      "use strict";
      return Component.extend({
          defaults: {
              template: 'Mp_Accountmanager/checkout/summary/customdiscount'
          },
          total_tmp: quote.getTotals(),
          isTaxDisplayedInGrandTotal: window.checkoutConfig.includeTaxInGrandTotal || false,
          isDisplayedCustomdiscount : function(){
              return true;
          },
          getCustomDiscount : function(){
              return total_tmp.getSegment('coupondiscount_total').value;
          }
      });
  }
);

but i cannot set the value please help someone to solve this issue and can anybody know how to get quote value in .js file

2
  • Don't understand,Where you want to achieve this.
    – Amit Bera
    Commented Mar 20, 2018 at 13:53
  • on cart page i want to display discount which i set in .phtml file @AmitBera
    – Jaimin
    Commented Mar 20, 2018 at 13:54

1 Answer 1

2

Try below code

define(
  [
      'jquery',
       'Magento_Checkout/js/view/summary/abstract-total',
       'Magento_Checkout/js/model/quote',
       'Magento_Catalog/js/price-utils',
       'Magento_Checkout/js/model/totals'
  ],
  function ($,Component, quote, priceUtils, totals) {
      "use strict";
      return Component.extend({
          defaults: {
              template: 'Mp_Accountmanager/checkout/summary/customdiscount'
          },
          total_tmp: quote.getTotals(),
          isTaxDisplayedInGrandTotal: window.checkoutConfig.includeTaxInGrandTotal || false,
          isDisplayedCustomdiscount : function(){
              return true;
          },
          getCustomDiscount : function(){
              return this.getFormattedPrice(total_tmp.getSegment('coupondiscount_total').value);
          }
      });
  }
);
2
  • Can you explain return this.getFormattedPrice(total_tmp.getSegment('coupondiscount_total').value); Commented Jul 31, 2018 at 6:47
  • This will return the coupon price total_tmp.getSegment('coupondiscount_total').value and this.getFormattedPrice() is use for formatting the price value it add the currency symbol Commented Jul 31, 2018 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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