feat(dashboard,cart,types,utils): refine order details summary (#13313)
* feat(dashboard,types,utils): refine order details summary * fix tests * changeset * ui corrections * tests again * weird tests failing * revert update to subtotal * revert http tests too * comments * move credit lines so it makes more sense * remove currency codes and add bold prices * add new properties in default for storefront * minor to patch * remove bold on things that should be * olis comment about taxes * remove bold from shipping
This commit is contained in:
@@ -76,6 +76,7 @@ describe("Total calculation", function () {
|
||||
item_total: 73.5,
|
||||
item_subtotal: 65,
|
||||
item_tax_total: 8.5,
|
||||
item_discount_total: 0,
|
||||
original_total: 73.5,
|
||||
original_tax_total: 8.5,
|
||||
original_item_subtotal: 65,
|
||||
@@ -149,6 +150,7 @@ describe("Total calculation", function () {
|
||||
item_total: 99,
|
||||
item_subtotal: 100,
|
||||
item_tax_total: 9,
|
||||
item_discount_total: 11,
|
||||
original_item_total: 110,
|
||||
original_item_subtotal: 100,
|
||||
original_item_tax_total: 10,
|
||||
@@ -350,12 +352,14 @@ describe("Total calculation", function () {
|
||||
item_total: 95.7,
|
||||
item_subtotal: 99,
|
||||
item_tax_total: 8.7,
|
||||
item_discount_total: 13.2,
|
||||
original_item_total: 108.9,
|
||||
original_item_subtotal: 99,
|
||||
original_item_tax_total: 9.9,
|
||||
shipping_total: 95.7,
|
||||
shipping_subtotal: 99,
|
||||
shipping_tax_total: 8.7,
|
||||
shipping_discount_total: 13.2,
|
||||
original_shipping_tax_total: 9.9,
|
||||
original_shipping_subtotal: 99,
|
||||
original_shipping_total: 108.9,
|
||||
@@ -444,6 +448,7 @@ describe("Total calculation", function () {
|
||||
item_total: 100,
|
||||
item_subtotal: 90.9090909090909,
|
||||
item_tax_total: 9.090909090909092,
|
||||
item_discount_total: 0,
|
||||
original_item_total: 100,
|
||||
original_item_subtotal: 90.9090909090909,
|
||||
original_item_tax_total: 9.090909090909092,
|
||||
@@ -486,6 +491,7 @@ describe("Total calculation", function () {
|
||||
item_total: 110,
|
||||
item_subtotal: 100,
|
||||
item_tax_total: 10,
|
||||
item_discount_total: 0,
|
||||
original_item_total: 110,
|
||||
original_item_subtotal: 100,
|
||||
original_item_tax_total: 10,
|
||||
@@ -548,6 +554,7 @@ describe("Total calculation", function () {
|
||||
item_total: 210,
|
||||
item_subtotal: 190.9090909090909,
|
||||
item_tax_total: 19.09090909090909,
|
||||
item_discount_total: 0,
|
||||
original_item_total: 210,
|
||||
original_item_subtotal: 190.9090909090909,
|
||||
original_item_tax_total: 19.09090909090909,
|
||||
@@ -638,6 +645,7 @@ describe("Total calculation", function () {
|
||||
item_subtotal: 100,
|
||||
item_tax_total: 18.333333333333332,
|
||||
item_total: 110,
|
||||
item_discount_total: 10,
|
||||
|
||||
credit_line_subtotal: 0,
|
||||
credit_line_tax_total: 0,
|
||||
@@ -749,12 +757,14 @@ describe("Total calculation", function () {
|
||||
item_total: 88,
|
||||
item_subtotal: 100,
|
||||
item_tax_total: 8,
|
||||
item_discount_total: 22,
|
||||
original_item_total: 110,
|
||||
original_item_subtotal: 100,
|
||||
original_item_tax_total: 10,
|
||||
shipping_total: 25.3,
|
||||
shipping_subtotal: 25,
|
||||
shipping_tax_total: 2.3,
|
||||
shipping_discount_total: 2.2,
|
||||
original_shipping_tax_total: 2.5,
|
||||
original_shipping_subtotal: 25,
|
||||
original_shipping_total: 27.5,
|
||||
@@ -866,6 +876,7 @@ describe("Total calculation", function () {
|
||||
item_total: 88,
|
||||
item_subtotal: 100,
|
||||
item_tax_total: 8,
|
||||
item_discount_total: 22,
|
||||
original_item_total: 110,
|
||||
original_item_subtotal: 100,
|
||||
original_item_tax_total: 10,
|
||||
@@ -942,6 +953,7 @@ describe("Total calculation", function () {
|
||||
item_total: 0,
|
||||
item_subtotal: 119,
|
||||
item_tax_total: 0,
|
||||
item_discount_total: 141.61,
|
||||
original_item_total: 141.61,
|
||||
original_item_subtotal: 119,
|
||||
original_item_tax_total: 22.61,
|
||||
@@ -1005,6 +1017,7 @@ describe("Total calculation", function () {
|
||||
discount_total: 0,
|
||||
item_subtotal: 100,
|
||||
item_tax_total: 19,
|
||||
item_discount_total: 0,
|
||||
item_total: 119,
|
||||
items: [
|
||||
{
|
||||
@@ -1048,6 +1061,7 @@ describe("Total calculation", function () {
|
||||
item_subtotal: 119,
|
||||
item_tax_total: 22.61,
|
||||
item_total: 141.61,
|
||||
item_discount_total: 0,
|
||||
items: [
|
||||
{
|
||||
discount_subtotal: 0,
|
||||
@@ -1090,6 +1104,7 @@ describe("Total calculation", function () {
|
||||
item_subtotal: 219,
|
||||
item_tax_total: 41.61,
|
||||
item_total: 260.61,
|
||||
item_discount_total: 0,
|
||||
items: [
|
||||
{
|
||||
discount_subtotal: 0,
|
||||
@@ -1176,6 +1191,7 @@ describe("Total calculation", function () {
|
||||
item_subtotal: 100,
|
||||
item_tax_total: 0,
|
||||
item_total: 0,
|
||||
item_discount_total: 119,
|
||||
items: [
|
||||
{
|
||||
adjustments: [
|
||||
|
||||
@@ -4,8 +4,8 @@ import { calculateCreditLinesTotal } from "../credit-lines"
|
||||
import { GetItemTotalInput, getLineItemsTotals } from "../line-item"
|
||||
import { MathBN } from "../math"
|
||||
import {
|
||||
GetShippingMethodTotalInput,
|
||||
getShippingMethodsTotals,
|
||||
GetShippingMethodTotalInput,
|
||||
} from "../shipping-method"
|
||||
import { transformPropertiesToBigNumber } from "../transform-properties-to-bignumber"
|
||||
|
||||
@@ -86,23 +86,19 @@ export function decorateCartTotals(
|
||||
|
||||
let itemsSubtotal = MathBN.convert(0)
|
||||
let itemsTotal = MathBN.convert(0)
|
||||
|
||||
let itemsOriginalTotal = MathBN.convert(0)
|
||||
let itemsOriginalSubtotal = MathBN.convert(0)
|
||||
|
||||
let itemsTaxTotal = MathBN.convert(0)
|
||||
|
||||
let itemsOriginalTaxTotal = MathBN.convert(0)
|
||||
let itemsDiscountTotal = MathBN.convert(0)
|
||||
|
||||
let shippingSubtotal = MathBN.convert(0)
|
||||
let shippingTotal = MathBN.convert(0)
|
||||
|
||||
let shippingOriginalTotal = MathBN.convert(0)
|
||||
let shippingOriginalSubtotal = MathBN.convert(0)
|
||||
|
||||
let shippingTaxTotal = MathBN.convert(0)
|
||||
|
||||
let shippingOriginalTaxTotal = MathBN.convert(0)
|
||||
let shippingDiscountTotal = MathBN.convert(0)
|
||||
|
||||
const cartItems = items.map((item, index) => {
|
||||
const itemTotals = Object.assign(item, itemsTotals[item.id ?? index] ?? {})
|
||||
@@ -128,15 +124,16 @@ export function decorateCartTotals(
|
||||
itemsTotal = MathBN.add(itemsTotal, itemTotal)
|
||||
itemsOriginalTotal = MathBN.add(itemsOriginalTotal, itemOriginalTotal)
|
||||
itemsOriginalSubtotal = MathBN.add(itemsOriginalSubtotal, itemSubtotal)
|
||||
|
||||
itemsSubtotal = MathBN.add(itemsSubtotal, itemSubtotal)
|
||||
|
||||
itemsTaxTotal = MathBN.add(itemsTaxTotal, itemTaxTotal)
|
||||
|
||||
itemsOriginalTaxTotal = MathBN.add(
|
||||
itemsOriginalTaxTotal,
|
||||
itemOriginalTaxTotal
|
||||
)
|
||||
itemsDiscountTotal = MathBN.add(
|
||||
itemsDiscountTotal,
|
||||
itemDiscountTotal
|
||||
)
|
||||
|
||||
for (const key of Object.values(optionalFields)) {
|
||||
if (key in itemTotals) {
|
||||
@@ -156,48 +153,45 @@ export function decorateCartTotals(
|
||||
|
||||
subtotal = MathBN.add(subtotal, shippingMethodTotals.subtotal)
|
||||
|
||||
shippingSubtotal = MathBN.add(
|
||||
shippingSubtotal,
|
||||
shippingMethodTotals.subtotal
|
||||
)
|
||||
|
||||
shippingTotal = MathBN.add(shippingTotal, shippingMethodTotals.total)
|
||||
|
||||
shippingOriginalTotal = MathBN.add(
|
||||
shippingOriginalTotal,
|
||||
shippingMethodTotals.original_total
|
||||
)
|
||||
|
||||
shippingOriginalSubtotal = MathBN.add(
|
||||
shippingOriginalSubtotal,
|
||||
shippingMethodTotals.subtotal
|
||||
)
|
||||
|
||||
shippingTaxTotal = MathBN.add(
|
||||
shippingTaxTotal,
|
||||
shippingMethodTotals.tax_total
|
||||
)
|
||||
|
||||
shippingOriginalTaxTotal = MathBN.add(
|
||||
shippingOriginalTaxTotal,
|
||||
shippingMethodTotals.original_tax_total
|
||||
)
|
||||
|
||||
discountTotal = MathBN.add(
|
||||
discountTotal,
|
||||
shippingMethodTotals.discount_total
|
||||
)
|
||||
|
||||
discountSubtotal = MathBN.add(
|
||||
discountSubtotal,
|
||||
shippingMethodTotals.discount_subtotal
|
||||
)
|
||||
|
||||
discountTaxTotal = MathBN.add(
|
||||
discountTaxTotal,
|
||||
shippingMethodTotals.discount_tax_total
|
||||
)
|
||||
|
||||
shippingSubtotal = MathBN.add(
|
||||
shippingSubtotal,
|
||||
shippingMethodTotals.subtotal
|
||||
)
|
||||
shippingTotal = MathBN.add(shippingTotal, shippingMethodTotals.total)
|
||||
shippingOriginalTotal = MathBN.add(
|
||||
shippingOriginalTotal,
|
||||
shippingMethodTotals.original_total
|
||||
)
|
||||
shippingOriginalSubtotal = MathBN.add(
|
||||
shippingOriginalSubtotal,
|
||||
shippingMethodTotals.subtotal
|
||||
)
|
||||
shippingTaxTotal = MathBN.add(
|
||||
shippingTaxTotal,
|
||||
shippingMethodTotals.tax_total
|
||||
)
|
||||
shippingOriginalTaxTotal = MathBN.add(
|
||||
shippingOriginalTaxTotal,
|
||||
shippingMethodTotals.original_tax_total
|
||||
)
|
||||
shippingDiscountTotal = MathBN.add(
|
||||
shippingDiscountTotal,
|
||||
shippingMethodTotals.discount_total
|
||||
)
|
||||
|
||||
return shippingMethodTotals
|
||||
})
|
||||
|
||||
@@ -250,6 +244,7 @@ export function decorateCartTotals(
|
||||
cart.item_total = new BigNumber(itemsTotal)
|
||||
cart.item_subtotal = new BigNumber(itemsSubtotal)
|
||||
cart.item_tax_total = new BigNumber(itemsTaxTotal)
|
||||
cart.item_discount_total = new BigNumber(itemsDiscountTotal)
|
||||
|
||||
cart.original_item_total = new BigNumber(itemsOriginalTotal)
|
||||
cart.original_item_subtotal = new BigNumber(itemsOriginalSubtotal)
|
||||
@@ -265,6 +260,7 @@ export function decorateCartTotals(
|
||||
cart.shipping_total = new BigNumber(shippingTotal)
|
||||
cart.shipping_subtotal = new BigNumber(shippingSubtotal)
|
||||
cart.shipping_tax_total = new BigNumber(shippingTaxTotal)
|
||||
cart.shipping_discount_total = new BigNumber(shippingDiscountTotal)
|
||||
|
||||
cart.original_shipping_tax_total = new BigNumber(shippingOriginalTaxTotal)
|
||||
cart.original_shipping_subtotal = new BigNumber(shippingOriginalSubtotal)
|
||||
|
||||
Reference in New Issue
Block a user