Skip to content

Commit dbd80fe

Browse files
authored
feat(core): show sale price for line items in Cart (#2803)
1 parent 215316a commit dbd80fe

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

.changeset/slick-apples-spend.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
"@bigcommerce/catalyst-core": patch
3+
---
4+
5+
- Added optional `salePrice?: string` property to the `CartLineItem` interface
6+
- Cart UI now displays sale prices with a strikethrough on the original price when `salePrice` is provided and differs from `price`
7+
8+
## Migration
9+
10+
If you're using the `Cart` component with custom line items, you can now optionally include a `salePrice` property:
11+
12+
```tsx
13+
const lineItems = [
14+
{
15+
// ... other properties
16+
price: '$100.00',
17+
salePrice: '$80.00', // Optional: when provided, displays as strikethrough price + sale price
18+
},
19+
];
20+
```
21+
22+
### Backward Compatibility
23+
24+
This change is **fully backward compatible**. The `salePrice` property is optional, so existing implementations will continue to work without modification. If `salePrice` is not provided or equals `price`, only the regular price will be displayed.

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,11 @@ export const PhysicalItemFragment = graphql(`
1919
quantity
2020
productEntityId
2121
variantEntityId
22-
extendedListPrice {
23-
currencyCode
24-
value
25-
}
26-
extendedSalePrice {
27-
currencyCode
28-
value
29-
}
30-
originalPrice {
22+
listPrice {
3123
currencyCode
3224
value
3325
}
34-
listPrice {
26+
salePrice {
3527
currencyCode
3628
value
3729
}
@@ -79,19 +71,11 @@ export const DigitalItemFragment = graphql(`
7971
quantity
8072
productEntityId
8173
variantEntityId
82-
extendedListPrice {
83-
currencyCode
84-
value
85-
}
86-
extendedSalePrice {
87-
currencyCode
88-
value
89-
}
90-
originalPrice {
74+
listPrice {
9175
currencyCode
9276
value
9377
}
94-
listPrice {
78+
salePrice {
9579
currencyCode
9680
value
9781
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ export default async function Cart({ params }: Props) {
130130
style: 'currency',
131131
currency: item.listPrice.currencyCode,
132132
}),
133+
salePrice: format.number(item.salePrice.value, {
134+
style: 'currency',
135+
currency: item.salePrice.currencyCode,
136+
}),
133137
subtitle: item.selectedOptions
134138
.map((option) => {
135139
switch (option.__typename) {

core/vibes/soul/sections/cart/client.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface CartLineItem {
4141
subtitle: string;
4242
quantity: number;
4343
price: string;
44+
salePrice?: string;
4445
href?: string;
4546
}
4647

@@ -558,8 +559,13 @@ function CounterForm({
558559
<form {...getFormProps(form)} action={action}>
559560
<input {...getInputProps(fields.id, { type: 'hidden' })} key={fields.id.id} />
560561
<div className="flex w-full flex-wrap items-center gap-x-5 gap-y-2">
561-
<span className="font-medium @xl:ml-auto">{lineItem.price}</span>
562-
562+
{lineItem.salePrice && lineItem.salePrice !== lineItem.price ? (
563+
<span className="font-medium @xl:ml-auto">
564+
<span className="line-through">{lineItem.price}</span> {lineItem.salePrice}
565+
</span>
566+
) : (
567+
<span className="font-medium @xl:ml-auto">{lineItem.price}</span>
568+
)}
563569
{/* Counter */}
564570
<div className="flex items-center rounded-lg border border-[var(--cart-counter-border,hsl(var(--contrast-100)))]">
565571
<button
@@ -604,7 +610,6 @@ function CounterForm({
604610
/>
605611
</button>
606612
</div>
607-
608613
<button
609614
aria-label={deleteLabel}
610615
className="group -ml-1 flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition-colors duration-300 hover:bg-[var(--cart-button-background,hsl(var(--contrast-100)))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--cart-focus,hsl(var(--primary)))] focus-visible:ring-offset-4"

0 commit comments

Comments
 (0)