Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fulfillmentTotalMoneyObject = {
amount: fulfillmentTotal,
currencyCode: cart.currencyCode
};
}
let taxTotalMoneyObject = null;
let effectiveTaxRateObject = null;
if (taxTotal !== null) {
taxTotalMoneyObject = {
amount: taxTotal,
currencyCode: cart.currencyCode
};
if (taxSummary) {
const effectiveTaxRate = taxSummary.tax / taxSummary.taxableAmount;
effectiveTaxRateObject = getRateObjectForRate(effectiveTaxRate);
}
}
fulfillmentGroups = fulfillmentGroups.map((fulfillmentGroup) => xformCartFulfillmentGroup(fulfillmentGroup, cart));
fulfillmentGroups = fulfillmentGroups.filter((group) => !!group); // filter out nulls
return {
fulfillmentGroups,
summary: {
discountTotal: {
amount: discountTotal,
currencyCode: cart.currencyCode
},
effectiveTaxRate: effectiveTaxRateObject,
fulfillmentTotal: fulfillmentTotalMoneyObject,
itemTotal: {
fulfillmentTotalMoneyObject = {
amount: fulfillmentTotal,
currencyCode: cart.currencyCode
};
}
let taxTotalMoneyObject = null;
let effectiveTaxRateObject = null;
if (taxTotal !== null) {
taxTotalMoneyObject = {
amount: taxTotal,
currencyCode: cart.currencyCode
};
if (taxSummary) {
const effectiveTaxRate = taxSummary.tax / taxSummary.taxableAmount;
effectiveTaxRateObject = getRateObjectForRate(effectiveTaxRate);
}
}
fulfillmentGroups = fulfillmentGroups.map((fulfillmentGroup) => xformCartFulfillmentGroup(fulfillmentGroup, cart));
fulfillmentGroups = fulfillmentGroups.filter((group) => !!group); // filter out nulls
return {
fulfillmentGroups,
summary: {
discountTotal: {
amount: discountTotal,
currencyCode: cart.currencyCode
},
effectiveTaxRate: effectiveTaxRateObject,
fulfillmentTotal: fulfillmentTotalMoneyObject,
itemTotal: {
const totalShippingAmount = totalShipping.reduce((acc, value) => acc + value, 0);
const totalSubtotalAmount = totalSubtotal.reduce((acc, value) => acc + value, 0);
const totalSurchargesAmount = totalSurcharges.reduce((acc, value) => acc + value, 0);
const totalTaxableAmountAmount = totalTaxableAmount.reduce((acc, value) => acc + value, 0);
const totalTaxesAmount = totalTaxes.reduce((acc, value) => acc + value, 0);
const totalTotalAmount = totalTotal.reduce((acc, value) => acc + value, 0);
// Calculate effective tax rate of combined fulfillmentGroups
const effectiveTaxRate = totalTaxableAmountAmount > 0 ? totalTaxesAmount / totalTaxableAmountAmount : 0;
return {
discountTotal: {
amount: totalDiscountsAmount,
currencyCode
},
effectiveTaxRate: getRateObjectForRate(effectiveTaxRate),
fulfillmentTotal: {
amount: totalShippingAmount,
currencyCode
},
itemTotal: {
amount: totalSubtotalAmount,
currencyCode
},
surchargeTotal: {
amount: totalSurchargesAmount,
currencyCode
},
taxableAmount: {
amount: totalTaxableAmountAmount,
currencyCode
},
taxes: taxSummary.taxes.map((calculatedTax) => ({
...calculatedTax,
tax: {
currencyCode,
amount: calculatedTax.tax
},
taxableAmount: {
currencyCode,
amount: calculatedTax.taxableAmount
},
taxRate: getRateObjectForRate(calculatedTax.taxRate)
}))
};
return orderItem.taxes.map((calculatedTax) => ({
...calculatedTax,
tax: {
currencyCode,
amount: calculatedTax.tax
},
taxableAmount: {
currencyCode,
amount: calculatedTax.taxableAmount
},
taxRate: getRateObjectForRate(calculatedTax.taxRate)
}));
}