Skip to content

Commit

Permalink
fix: multi payments amount always updating to half of the cart total
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateus Picoloto committed Mar 4, 2024
1 parent 836a804 commit 8be780b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
19 changes: 19 additions & 0 deletions view/frontend/web/js/core/checkout/PaymentMethodController.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ define([

this.platformConfig.updateTotals.totals.subscribe(function(){
if (_self.methodCode === 'twocreditcards' || _self.methodCode === 'boletoCreditcard') {
let totalAmount = 0;
const separator = '.';
for (let i = 0, len = _self.formObject.numberOfPaymentForms; i < len; i++) {
let amount = _self.formObject[i].inputAmount.val();
if (amount === undefined) {
continue;
}
amount = amount.replace(_self.platformConfig.currency.decimalSeparator, separator);

totalAmount += parseFloat(amount);
}

if (totalAmount === _self.platformConfig.updateTotals.getTotals()().grand_total) {
return;
}

for (let i = 0, len = _self.formObject.numberOfPaymentForms; i < len; i++) {
_self.fillCardAmount(_self.formObject[i], 2, i);
_self.fillInstallments(_self.formObject[i]);
Expand Down Expand Up @@ -479,6 +495,9 @@ define([
let sumTotal = (parseFloat(valueCard) + parseFloat(valueBoleto));

sumTotal = (sumTotal + parseFloat(sumInterestTotal)).toString();
if (sumInterestTotal === undefined) {
sumInterestTotal = 0.0;
}
sumInterestTotal = sumInterestTotal.toString();

return { sumTotal, sumInterestTotal };
Expand Down
6 changes: 0 additions & 6 deletions view/frontend/web/js/core/models/BoletoCreditcardModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ define([
'cc_cc_amount': this.formObject[1].inputAmount.val(),
'cc_cc_tax_amount': this.formObject[1].creditCardInstallments.find(':selected').attr('interest'),
'cc_type': this.formObject[1].creditCardBrand.val(),
'cc_last_4': this.getLastFourNumbers(1),
'cc_cid': this.formObject[1].creditCardCvv.val(),
'cc_ss_start_year': this.formObject[1].creditCardExpYear.val(),
'cc_ss_start_month': this.formObject[1].creditCardExpMonth.val(),
'cc_number': this.formObject[1].creditCardNumber.val(),
'cc_owner': this.formObject[1].creditCardHolderName.val(),
'cc_savecard': saveThiscard,
'cc_saved_card': this.formObject[1].savedCreditCardSelect.val(),
'cc_installments': this.formObject[1].creditCardInstallments.val(),
Expand Down
12 changes: 0 additions & 12 deletions view/frontend/web/js/core/models/TwoCreditcardsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ define([
'cc_first_card_amount': this.formObject[0].inputAmount.val(),
'cc_first_card_tax_amount': this.formObject[0].creditCardInstallments.find(':selected').attr('interest'),
'cc_type_first': this.formObject[0].creditCardBrand.val(),
'cc_last_4_first': this.getLastFourNumbers(0),
'cc_cid_first': this.formObject[0].creditCardCvv.val(),
'cc_exp_year_first': this.formObject[0].creditCardExpYear.val(),
'cc_exp_month_first': this.formObject[0].creditCardExpMonth.val(),
'cc_number_first': this.formObject[0].creditCardNumber.val(),
'cc_owner_first': this.formObject[0].creditCardHolderName.val(),
'cc_savecard_first' : saveFirstCard,
'cc_saved_card_first' : this.formObject[0].savedCreditCardSelect.val(),
'cc_installments_first': this.formObject[0].creditCardInstallments.val(),
Expand All @@ -180,12 +174,6 @@ define([
'cc_second_card_amount': this.formObject[1].inputAmount.val(),
'cc_second_card_tax_amount': this.formObject[1].creditCardInstallments.find(':selected').attr('interest'),
'cc_type_second': this.formObject[1].creditCardBrand.val(),
'cc_last_4_second': this.getLastFourNumbers(1),
'cc_cid_second': this.formObject[1].creditCardCvv.val(),
'cc_exp_year_second': this.formObject[1].creditCardExpYear.val(),
'cc_exp_month_second': this.formObject[1].creditCardExpMonth.val(),
'cc_number_second': this.formObject[1].creditCardNumber.val(),
'cc_owner_second': this.formObject[1].creditCardHolderName.val(),
'cc_savecard_second' : saveSecondCard,
'cc_saved_card_second' : this.formObject[1].savedCreditCardSelect.val(),
'cc_installments_second': this.formObject[1].creditCardInstallments.val(),
Expand Down

0 comments on commit 8be780b

Please sign in to comment.