Skip to content

Commit 24cc310

Browse files
fix(core): TRAC-294 show manual checkout discounts in cart summary (#3002)
1 parent ec92930 commit 24cc310

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

.changeset/cold-foxes-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst-core": patch
3+
---
4+
5+
Fix cart summary Discounts row not showing manual discounts applied via the Management Checkout API

core/app/[locale]/(default)/cart/page-data.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export const PhysicalItemFragment = graphql(`
2828
currencyCode
2929
value
3030
}
31+
discountedAmount {
32+
currencyCode
33+
value
34+
}
3135
selectedOptions {
3236
__typename
3337
entityId
@@ -87,6 +91,10 @@ export const DigitalItemFragment = graphql(`
8791
currencyCode
8892
value
8993
}
94+
discountedAmount {
95+
currencyCode
96+
value
97+
}
9098
selectedOptions {
9199
__typename
92100
entityId

core/app/[locale]/(default)/cart/page.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ export default async function Cart({ params }: Props) {
213213
const totalCouponDiscount =
214214
checkout?.coupons.reduce((sum, coupon) => sum + coupon.discountedAmount.value, 0) ?? 0;
215215

216+
const totalLineItemDiscount = [
217+
...cart.lineItems.physicalItems,
218+
...cart.lineItems.digitalItems,
219+
].reduce((sum, item) => sum + item.discountedAmount.value, 0);
220+
221+
const totalDiscount = cart.discountedAmount.value + totalLineItemDiscount;
222+
216223
const giftCertificatesSummary =
217224
checkout?.giftCertificates.reduce<Array<{ code: string; used: number }>>((acc, c) => {
218225
acc.push({
@@ -278,10 +285,10 @@ export default async function Cart({ params }: Props) {
278285
currency: cart.currencyCode,
279286
}),
280287
},
281-
cart.discountedAmount.value > 0
288+
totalDiscount > 0
282289
? {
283290
label: t('CheckoutSummary.discounts'),
284-
value: `-${format.number(cart.discountedAmount.value, {
291+
value: `-${format.number(totalDiscount, {
285292
style: 'currency',
286293
currency: cart.currencyCode,
287294
})}`,

0 commit comments

Comments
 (0)