Skip to content

Commit

Permalink
Merge pull request #14 from Coosos/feature-use-mixin-instead-of-map
Browse files Browse the repository at this point in the history
Use mixin instead of map
  • Loading branch information
mageprince authored Feb 20, 2021
2 parents d014662 + 571639f commit e7f84f1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 64 deletions.
11 changes: 6 additions & 5 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var config = {
map: {
'*': {
'Magento_Checkout/js/action/select-payment-method':
'Mageprince_Paymentfee/js/action/payment/select-payment-method'
let config = {
config: {
mixins: {
'Magento_Checkout/js/action/select-payment-method': {
'Mageprince_Paymentfee/js/action/payment/select-payment-method-mixin': true
}
}
}
};
59 changes: 20 additions & 39 deletions view/frontend/web/js/action/checkout/cart/totals.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,30 @@
define(
[
'ko',
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/resource-url-manager',
'Magento_Checkout/js/model/payment-service',
'mage/storage',
'mage/url',
'Magento_Checkout/js/action/get-totals',
'mage/translate',
'Magento_Checkout/js/model/payment/method-list'
],
function(
ko,
$,
quote,
urlManager,
paymentService,
storage,
urlBuilder,
getTotalsAction
) {
define([
'ko',
'jquery',
'Magento_Checkout/js/model/quote',
'mage/storage',
'mage/url',
'Magento_Checkout/js/action/get-totals'
], function (ko, $, quote, storage, urlBuilder, getTotalsAction) {
'use strict';

return function (isLoading, payment) {
var $isEnabled = window.checkoutConfig.mageprince_paymentfee.isEnabled;
if($isEnabled != 0) {
var serviceUrl = urlBuilder.build('paymentfee/calculate/paymentfee');
let isEnabled = window.checkoutConfig.mageprince_paymentfee.isEnabled;
if (isEnabled) {
return storage.post(
serviceUrl,
urlBuilder.build('paymentfee/calculate/paymentfee'),
JSON.stringify({payment: payment})
).done(
function (response) {
if (response) {
var deferred = $.Deferred();
isLoading(false);
getTotalsAction([], deferred);
}
}
).fail(
function (response) {
).done(function (response) {
if (response) {
let deferred = $.Deferred();

isLoading(false);
getTotalsAction([], deferred);
}
);
}).fail(function () {
isLoading(false);
});
}
}
};
}
);
25 changes: 25 additions & 0 deletions view/frontend/web/js/action/payment/select-payment-method-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
define(
[
'mage/utils/wrapper',
'ko',
'Mageprince_Paymentfee/js/action/checkout/cart/totals'
],
function (wrapper, ko, totals) {
'use strict';

let isLoading = ko.observable(false);

return function (selectPaymentMethodAction) {
return wrapper.wrap(selectPaymentMethodAction, function (originalSelectPaymentMethodAction, paymentMethod) {
originalSelectPaymentMethodAction(paymentMethod);

if (!require.defined('Magento_SalesRule/js/action/select-payment-method-mixin')) {
let isEnabled = window.checkoutConfig.mageprince_paymentfee.isEnabled;
if (isEnabled) {
totals(isLoading, paymentMethod['method']);
}
}
});
};
}
);
20 changes: 0 additions & 20 deletions view/frontend/web/js/action/payment/select-payment-method.js

This file was deleted.

0 comments on commit e7f84f1

Please sign in to comment.