-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1059 from buckaroo-it/BP-3778-The-transaction-cal…
…culations-are-not-being-compiled-properly BP-3778-The-transaction-calculations-are-not-being-compiled-properly
- Loading branch information
Showing
4 changed files
with
139 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
view/frontend/web/js/view/checkout/summary/grand-total.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** | ||
* @api | ||
*/ | ||
|
||
define([ | ||
'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: { | ||
isFullTaxSummaryDisplayed: window.checkoutConfig.isFullTaxSummaryDisplayed || false, | ||
template: 'Buckaroo_Magento2/checkout/summary/grand-total' | ||
}, | ||
totals: quote.getTotals(), | ||
isTaxDisplayedInGrandTotal: window.checkoutConfig.includeTaxInGrandTotal || false, | ||
|
||
/** | ||
* @return {*} | ||
*/ | ||
isDisplayed: function () { | ||
return this.isFullMode(); | ||
}, | ||
|
||
/** | ||
* @return {*|String} | ||
*/ | ||
getValue: function () { | ||
var price = 0; | ||
|
||
if (this.totals()) { | ||
price = totals.getSegment('grand_total').value; | ||
|
||
if(!isNaN(parseFloat(this.getAlreadyPayTotal()))){ | ||
price = parseFloat(price) - parseFloat(this.getAlreadyPayTotal()); | ||
} | ||
} | ||
|
||
return this.getFormattedPrice(price); | ||
}, | ||
|
||
/** | ||
* @return {*|String} | ||
*/ | ||
getBaseValue: function () { | ||
var price = 0; | ||
|
||
if (this.totals()) { | ||
price = this.totals()['base_grand_total']; | ||
} | ||
|
||
return priceUtils.formatPriceLocale(price, quote.getBasePriceFormat()); | ||
}, | ||
|
||
/** | ||
* @return {*} | ||
*/ | ||
getGrandTotalExclTax: function () { | ||
var total = this.totals(), | ||
amount; | ||
|
||
if (!total) { | ||
return 0; | ||
} | ||
|
||
amount = total['grand_total'] - total['tax_amount']; | ||
|
||
if (amount < 0) { | ||
amount = 0; | ||
} | ||
|
||
return this.getFormattedPrice(amount); | ||
}, | ||
|
||
/** | ||
* @return {Boolean} | ||
*/ | ||
isBaseGrandTotalDisplayNeeded: function () { | ||
var total = this.totals(); | ||
|
||
if (!total) { | ||
return false; | ||
} | ||
|
||
return total['base_currency_code'] != total['quote_currency_code']; //eslint-disable-line eqeqeq | ||
}, | ||
|
||
getAlreadyPayTotal : function () { | ||
var buckarooFeeSegment = totals.getSegment('buckaroo_already_paid'); | ||
try { | ||
if (buckarooFeeSegment.title) { | ||
var items = JSON.parse(buckarooFeeSegment.title); | ||
var total = 0; | ||
if ((typeof items === 'object') && (items.length > 0)) { | ||
for (var i = 0; i < items.length; i++) { | ||
total = parseFloat(total) + parseFloat(items[i].serviceamount); | ||
} | ||
return parseFloat(total).toFixed(2); | ||
} | ||
} | ||
} catch (e) { | ||
// console.log(e); | ||
} | ||
|
||
return parseFloat(buckarooFeeSegment.value).toFixed(2); | ||
} | ||
}); | ||
}); |