checkout-balance.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'jquery/ui'
  8. ], function ($) {
  9. 'use strict';
  10. $.widget('mage.checkoutBalance', {
  11. /**
  12. * Initialize store credit events
  13. * @private
  14. */
  15. _create: function () {
  16. this.eventData = {
  17. price: this.options.balance,
  18. totalPrice: 0
  19. };
  20. this.element.on('change', $.proxy(function (e) {
  21. if ($(e.target).is(':checked')) {
  22. this.eventData.price = -1 * this.options.balance;
  23. } else {
  24. if (this.options.amountSubstracted) { //eslint-disable-line no-lonely-if
  25. this.eventData.price = parseFloat(this.options.usedAmount);
  26. this.options.amountSubstracted = false;
  27. } else {
  28. this.eventData.price = parseFloat(this.options.balance);
  29. }
  30. }
  31. this.element.trigger('updateCheckoutPrice', this.eventData);
  32. }, this));
  33. }
  34. });
  35. return $.mage.checkoutBalance;
  36. });