override.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * This file is part of the Klarna KP module
  3. *
  4. * (c) Klarna Bank AB (publ)
  5. *
  6. * For the full copyright and license information, please view the NOTICE
  7. * and LICENSE files that were distributed with this source code.
  8. */
  9. /*jshint browser:true jquery:true*/
  10. /*global alert*/
  11. define([
  12. 'mage/utils/wrapper',
  13. 'Klarna_Kp/js/model/config',
  14. 'Magento_Checkout/js/model/full-screen-loader'
  15. ], function (wrapper, config, loader) {
  16. 'use strict';
  17. /**
  18. * This is needed to prevent the customer from a race condition between 'Place Order' and adding/removing a coupon,
  19. * giftcard, rewards points, etc.. as it affects order totals
  20. */
  21. return function (overriddenFunction) {
  22. return wrapper.wrap(overriddenFunction, function (originalAction) {
  23. if (!config.enabled) {
  24. return originalAction();
  25. }
  26. if (config.hasErrors()) {
  27. return originalAction();
  28. }
  29. loader.startLoader();
  30. return originalAction().then(function () {
  31. loader.stopLoader();
  32. });
  33. });
  34. };
  35. });