Skip to content

Commit d1b8660

Browse files
committed
@W-20542850 Remove promotion from Shipping Method summary view (#3563)
* W-20542850 Remove promotion from Shipping Method summary view * add translations
1 parent 86c140a commit d1b8660

File tree

7 files changed

+200
-111
lines changed

7 files changed

+200
-111
lines changed

packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-shipping-options.jsx

Lines changed: 22 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,18 @@ export default function ShippingOptions() {
248248
id: 'checkout_confirmation.label.free'
249249
})
250250

251-
let shippingPriceLabel = selectedMethodDisplayPrice
252-
if (selectedMethodDisplayPrice !== shippingItem.price) {
253-
const currentPrice =
254-
selectedMethodDisplayPrice === 0 ? freeLabel : selectedMethodDisplayPrice
255-
256-
shippingPriceLabel = formatMessage(
257-
{
258-
defaultMessage: 'Originally {originalPrice}, now {newPrice}',
259-
id: 'checkout_confirmation.label.shipping.strikethrough.price'
260-
},
261-
{
262-
originalPrice: shippingItem.price,
263-
newPrice: currentPrice
264-
}
265-
)
266-
}
251+
const shippingPriceLabel =
252+
selectedMethodDisplayPrice === 0
253+
? freeLabel
254+
: formatMessage(
255+
{
256+
defaultMessage: '{price}',
257+
id: 'checkout_confirmation.label.shipping.price'
258+
},
259+
{
260+
price: selectedMethodDisplayPrice
261+
}
262+
)
267263

268264
return (
269265
<ToggleCard
@@ -398,7 +394,6 @@ export default function ShippingOptions() {
398394
<SingleShipmentSummary
399395
selectedShippingMethod={selectedShippingMethod}
400396
selectedMethodDisplayPrice={selectedMethodDisplayPrice}
401-
shippingItem={shippingItem}
402397
shippingPriceLabel={shippingPriceLabel}
403398
currency={currency}
404399
freeLabel={freeLabel}
@@ -497,7 +492,6 @@ MultiShipmentSummary.propTypes = {
497492
const SingleShipmentSummary = ({
498493
selectedShippingMethod,
499494
selectedMethodDisplayPrice,
500-
shippingItem,
501495
shippingPriceLabel,
502496
currency,
503497
freeLabel
@@ -506,46 +500,21 @@ const SingleShipmentSummary = ({
506500
<ToggleCardSummary>
507501
<Flex justify="space-between" w="full">
508502
<Text>{selectedShippingMethod.name}</Text>
509-
<Flex alignItems="center" aria-label={shippingPriceLabel} role="group">
510-
<Text fontWeight="bold" aria-hidden="true" role="presentation">
511-
{selectedMethodDisplayPrice === 0 ? (
512-
freeLabel
513-
) : (
514-
<FormattedNumber
515-
value={selectedMethodDisplayPrice}
516-
style="currency"
517-
currency={currency}
518-
/>
519-
)}
520-
</Text>
521-
{selectedMethodDisplayPrice !== shippingItem.price && (
522-
<Text
523-
fontWeight="normal"
524-
textDecoration="line-through"
525-
color="gray.600"
526-
marginLeft={1}
527-
aria-hidden="true"
528-
role="presentation"
529-
>
530-
<FormattedNumber
531-
style="currency"
532-
currency={currency}
533-
value={shippingItem.price}
534-
/>
535-
</Text>
503+
<Text fontWeight="bold" aria-label={shippingPriceLabel}>
504+
{selectedMethodDisplayPrice === 0 ? (
505+
freeLabel
506+
) : (
507+
<FormattedNumber
508+
value={selectedMethodDisplayPrice}
509+
style="currency"
510+
currency={currency}
511+
/>
536512
)}
537-
</Flex>
513+
</Text>
538514
</Flex>
539515
<Text fontSize="sm" color="gray.700">
540516
{selectedShippingMethod.description}
541517
</Text>
542-
{shippingItem?.priceAdjustments?.map((adjustment) => {
543-
return (
544-
<Text key={adjustment.priceAdjustmentId} fontSize="sm" color="green.600">
545-
{adjustment.itemText}
546-
</Text>
547-
)
548-
})}
549518
</ToggleCardSummary>
550519
)
551520
}
@@ -556,15 +525,6 @@ SingleShipmentSummary.propTypes = {
556525
description: PropTypes.string
557526
}).isRequired,
558527
selectedMethodDisplayPrice: PropTypes.number.isRequired,
559-
shippingItem: PropTypes.shape({
560-
price: PropTypes.number,
561-
priceAdjustments: PropTypes.arrayOf(
562-
PropTypes.shape({
563-
priceAdjustmentId: PropTypes.string,
564-
itemText: PropTypes.string
565-
})
566-
)
567-
}),
568528
shippingPriceLabel: PropTypes.string.isRequired,
569529
currency: PropTypes.string.isRequired,
570530
freeLabel: PropTypes.string.isRequired

packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-shipping-options.test.js

Lines changed: 168 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ describe('ShippingOptions Component', () => {
432432
})
433433

434434
describe('in summary view (PAYMENT step)', () => {
435-
test('renders SingleShipmentSummary with price adjustments and strikethrough price', async () => {
435+
test('renders SingleShipmentSummary without price adjustments and strikethrough price', async () => {
436436
jest.resetModules()
437437

438438
jest.doMock(
@@ -500,7 +500,81 @@ describe('ShippingOptions Component', () => {
500500

501501
expect(screen.getAllByText('Standard Shipping').length).toBeGreaterThan(0)
502502
expect(screen.getAllByText('5-7 business days').length).toBeGreaterThan(0)
503-
expect(screen.getByText('50% off shipping!')).toBeInTheDocument()
503+
// Verify promotion text is NOT shown in summary view
504+
expect(screen.queryByText('50% off shipping!')).not.toBeInTheDocument()
505+
// Verify only the final price is shown (no strikethrough)
506+
// Price is formatted with currency code (US$4.99)
507+
expect(screen.getByText(/4\.99/)).toBeInTheDocument()
508+
// Verify original price with strikethrough is NOT shown
509+
expect(screen.queryByText(/9\.99/)).not.toBeInTheDocument()
510+
})
511+
512+
test('renders only final price in summary view when price differs from original', async () => {
513+
jest.resetModules()
514+
515+
jest.doMock(
516+
'@salesforce/retail-react-app/app/pages/checkout-one-click/util/checkout-context',
517+
() => ({
518+
useCheckout: jest.fn().mockReturnValue({
519+
step: 4,
520+
STEPS: {
521+
CONTACT_INFO: 0,
522+
PICKUP_ADDRESS: 1,
523+
SHIPPING_ADDRESS: 2,
524+
SHIPPING_OPTIONS: 3,
525+
PAYMENT: 4
526+
},
527+
goToStep: mockGoToStep,
528+
goToNextStep: mockGoToNextStep
529+
})
530+
})
531+
)
532+
jest.doMock('@salesforce/retail-react-app/app/hooks/use-current-customer', () => ({
533+
useCurrentCustomer: () => ({
534+
data: {customerId: 'test-customer-id', isRegistered: true}
535+
})
536+
}))
537+
jest.doMock('@salesforce/retail-react-app/app/hooks/use-current-basket', () => ({
538+
useCurrentBasket: () => ({
539+
data: {
540+
basketId: 'test-basket-id',
541+
shipments: [
542+
{
543+
shipmentId: 'me',
544+
shippingAddress: {address1: '123 Main St', city: 'Test City'},
545+
shippingMethod: {
546+
id: 'standard-shipping',
547+
name: 'Standard Shipping',
548+
description: '5-7 business days'
549+
}
550+
}
551+
],
552+
shippingItems: [
553+
{
554+
price: 9.99,
555+
priceAfterItemDiscount: 0,
556+
priceAdjustments: []
557+
}
558+
]
559+
},
560+
derivedData: {hasBasket: true, totalItems: 1, totalShippingCost: 0}
561+
})
562+
}))
563+
564+
const {renderWithProviders: localRenderWithProviders} = await import(
565+
'@salesforce/retail-react-app/app/utils/test-utils'
566+
)
567+
const module = await import(
568+
'@salesforce/retail-react-app/app/pages/checkout-one-click/partials/one-click-shipping-options'
569+
)
570+
571+
localRenderWithProviders(<module.default />)
572+
573+
// Verify "Free" is shown (final price is 0)
574+
// There may be multiple instances (edit view and summary view), so use getAllByText
575+
expect(screen.getAllByText('Free').length).toBeGreaterThan(0)
576+
// Verify original price is NOT shown
577+
expect(screen.queryByText(/9\.99/)).not.toBeInTheDocument()
504578
})
505579

506580
test('renders "Free" label when shipping cost is zero', async () => {
@@ -580,7 +654,8 @@ describe('ShippingOptions Component', () => {
580654

581655
localRenderWithProviders(<module.default />)
582656

583-
expect(screen.getByText('Free')).toBeInTheDocument()
657+
// There may be multiple instances (edit view and summary view), so use getAllByText
658+
expect(screen.getAllByText('Free').length).toBeGreaterThan(0)
584659
})
585660
})
586661

@@ -1014,6 +1089,96 @@ describe('ShippingOptions Component', () => {
10141089
screen.getByText('Jane Doe, 456 Oak Avenue, Seattle, WA, 98101')
10151090
).toBeInTheDocument()
10161091
})
1092+
1093+
test('displays shipping promotions in edit view for multi-shipment', async () => {
1094+
jest.resetModules()
1095+
1096+
const methodsWithPromos = {
1097+
defaultShippingMethodId: 'std',
1098+
applicableShippingMethods: [
1099+
{
1100+
id: 'std',
1101+
name: 'Standard Shipping',
1102+
description: '4-5 days',
1103+
price: 5.99,
1104+
shippingPromotions: [
1105+
{
1106+
promotionId: 'promo1',
1107+
calloutMsg: 'Free Shipping Amount Above 50'
1108+
}
1109+
]
1110+
},
1111+
{
1112+
id: 'exp',
1113+
name: 'Express Shipping',
1114+
description: 'Overnight',
1115+
price: 10,
1116+
shippingPromotions: []
1117+
}
1118+
]
1119+
}
1120+
1121+
jest.doMock(
1122+
'@salesforce/retail-react-app/app/pages/checkout-one-click/util/checkout-context',
1123+
() => ({
1124+
useCheckout: jest.fn().mockReturnValue({
1125+
step: 3,
1126+
STEPS: {
1127+
CONTACT_INFO: 0,
1128+
PICKUP_ADDRESS: 1,
1129+
SHIPPING_ADDRESS: 2,
1130+
SHIPPING_OPTIONS: 3,
1131+
PAYMENT: 4
1132+
},
1133+
goToStep: mockGoToStep,
1134+
goToNextStep: mockGoToNextStep
1135+
})
1136+
})
1137+
)
1138+
jest.doMock('@salesforce/retail-react-app/app/hooks/use-current-customer', () => ({
1139+
useCurrentCustomer: () => ({
1140+
data: {customerId: null, isRegistered: false}
1141+
})
1142+
}))
1143+
jest.doMock('@salesforce/retail-react-app/app/hooks/use-current-basket', () => ({
1144+
useCurrentBasket: () => ({
1145+
data: {
1146+
basketId: 'test-basket-id',
1147+
shipments: [
1148+
{
1149+
shipmentId: 'ship1',
1150+
shippingAddress: {
1151+
firstName: 'John',
1152+
lastName: 'Smith',
1153+
address1: '789 Elm Street',
1154+
city: 'Portland',
1155+
stateCode: 'OR',
1156+
postalCode: '97201'
1157+
},
1158+
shippingMethod: null
1159+
}
1160+
],
1161+
shippingItems: [{shipmentId: 'ship1', price: 0}]
1162+
},
1163+
derivedData: {hasBasket: true, totalItems: 1}
1164+
})
1165+
}))
1166+
1167+
const sdk = await import('@salesforce/commerce-sdk-react')
1168+
sdk.useShippingMethodsForShipment.mockReturnValue({data: methodsWithPromos})
1169+
1170+
const {renderWithProviders: localRenderWithProviders} = await import(
1171+
'@salesforce/retail-react-app/app/utils/test-utils'
1172+
)
1173+
const module = await import(
1174+
'@salesforce/retail-react-app/app/pages/checkout-one-click/partials/one-click-shipping-options'
1175+
)
1176+
1177+
localRenderWithProviders(<module.default />)
1178+
1179+
// Verify promotion text is shown in edit view
1180+
expect(screen.getByText('Free Shipping Amount Above 50')).toBeInTheDocument()
1181+
})
10171182
})
10181183

10191184
describe('multi-shipment summary view', () => {

packages/template-retail-react-app/app/static/translations/compiled/en-GB.json

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,22 +1147,10 @@
11471147
"value": "Shipping"
11481148
}
11491149
],
1150-
"checkout_confirmation.label.shipping.strikethrough.price": [
1151-
{
1152-
"type": 0,
1153-
"value": "Originally "
1154-
},
1155-
{
1156-
"type": 1,
1157-
"value": "originalPrice"
1158-
},
1159-
{
1160-
"type": 0,
1161-
"value": ", now "
1162-
},
1150+
"checkout_confirmation.label.shipping.price": [
11631151
{
11641152
"type": 1,
1165-
"value": "newPrice"
1153+
"value": "price"
11661154
}
11671155
],
11681156
"checkout_confirmation.label.subtotal": [

packages/template-retail-react-app/app/static/translations/compiled/en-US.json

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,22 +1147,10 @@
11471147
"value": "Shipping"
11481148
}
11491149
],
1150-
"checkout_confirmation.label.shipping.strikethrough.price": [
1151-
{
1152-
"type": 0,
1153-
"value": "Originally "
1154-
},
1155-
{
1156-
"type": 1,
1157-
"value": "originalPrice"
1158-
},
1159-
{
1160-
"type": 0,
1161-
"value": ", now "
1162-
},
1150+
"checkout_confirmation.label.shipping.price": [
11631151
{
11641152
"type": 1,
1165-
"value": "newPrice"
1153+
"value": "price"
11661154
}
11671155
],
11681156
"checkout_confirmation.label.subtotal": [

0 commit comments

Comments
 (0)