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

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

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);
          }
      });
  }
);
  • Can you explain return this.getFormattedPrice(total_tmp.getSegment('coupondiscount_total').value); – SURENDER SINGH Jul 31 '18 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 – Kushal Jul 31 '18 at 6:55

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.