Skip to content

Commit

Permalink
fix(core): use amount and discounts fields for cart summary (#659)
Browse files Browse the repository at this point in the history
* fix(core): use full discount amount for all line items

* fix(core): use cart amount to show total amount

* fix: revert key deletion

* chore: update changeset

* feat(core): add minus sign to discount
  • Loading branch information
jorgemoya committed Mar 15, 2024
1 parent 0ae1b1b commit 35e5c96
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-spies-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Use amount and discount values for cart summary in Cart page
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ export const CheckoutSummary = ({
<div className="flex justify-between border-t border-t-gray-200 py-4">
<span className="text-base font-semibold">{t('discounts')}</span>
<span className="text-base">
{currencyFormatter.format(checkoutSummary.totalDiscountedAmount.value)}
-{currencyFormatter.format(checkoutSummary.discountedAmount.value)}
</span>
</div>

<div className="flex justify-between border-t border-t-gray-200 py-4">
<span className="text-h5">{t('grandTotal')}</span>
<span className="text-h5">
{currencyFormatter.format(
checkoutSummary.totalExtendedSalePrice.value +
checkoutSummary.amount.value +
checkoutSummary.shippingCostTotal.value +
checkoutSummary.handlingCostTotal.value,
)}
Expand Down
25 changes: 6 additions & 19 deletions apps/core/client/queries/get-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export const GET_CART_QUERY = /* GraphQL */ `
extendedSalePrice {
...MoneyFields
}
discountedAmount {
...MoneyFields
}
selectedOptions {
__typename
entityId
Expand Down Expand Up @@ -60,6 +57,12 @@ export const GET_CART_QUERY = /* GraphQL */ `
}
}
}
amount {
...MoneyFields
}
discountedAmount {
...MoneyFields
}
}
}
}
Expand Down Expand Up @@ -91,27 +94,11 @@ export const getCart = cache(async (cartId?: string) => {
return acc + item.extendedListPrice.value;
}, 0);

const totalDiscountedAmount = cart.lineItems.physicalItems.reduce((acc, item) => {
return acc + item.discountedAmount.value;
}, 0);

const totalExtendedSalePrice = cart.lineItems.physicalItems.reduce((acc, item) => {
return acc + item.extendedSalePrice.value;
}, 0);

return {
...cart,
totalExtendedListPrice: {
currencyCode: cart.currencyCode,
value: totalExtendedListPrice,
},
totalDiscountedAmount: {
currencyCode: cart.currencyCode,
value: totalDiscountedAmount,
},
totalExtendedSalePrice: {
currencyCode: cart.currencyCode,
value: totalExtendedSalePrice,
},
};
});

0 comments on commit 35e5c96

Please sign in to comment.