Skip to content

Commit 2c809bb

Browse files
@W-21188588 Default to ECOM Shipping when OMS does not return shipping (#3639)
* Default to ECOM Shipping when OMS does not return shipping * Add changelog * lint fix * nit optional check * variable rename
1 parent 32ff733 commit 2c809bb

File tree

3 files changed

+69
-8
lines changed

3 files changed

+69
-8
lines changed

packages/template-retail-react-app/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Integrate Order History page to display data from OMS [#3581](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3581)
88
- Add shipping display support for OMS [#3588](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3588)
99
- BOPIS multishipment with OMS [#3613] (https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3613)
10+
- Default to ECOM shipments in case OMS has no shipments [#3639] (https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3639)
1011
- [Feature] Update passwordless login and password reset to use email mode by default. The mode can now be configured across the login page, auth modal, and checkout page [#3525](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3525)
1112
- Update "Continue Securely" button text to "Continue" for passwordless login [#3556](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3556)
1213
- Util function for passwordless callback URI [#3630](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3630)

packages/template-retail-react-app/app/pages/account/order-detail.jsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,18 @@ const AccountOrderDetail = () => {
137137
// Check if order has OMS data
138138
const isOmsOrder = useMemo(() => !!order?.omsData, [order?.omsData])
139139

140-
// Check if order is multi-shipment order
140+
const omsShipmentCount = order?.omsData?.shipments?.length ?? 0
141+
const ecomShipmentCount = order?.shipments?.length ?? 0
142+
143+
const hasOmsShipment = useMemo(() => omsShipmentCount > 0, [omsShipmentCount])
144+
141145
const isMultiShipmentOrder = useMemo(
142-
() => (order?.omsData?.shipments?.length ?? 0) > 1 || (order?.shipments?.length ?? 0) > 1,
143-
[isOmsOrder, order?.omsData?.shipments?.length, order?.shipments?.length]
146+
() => omsShipmentCount > 1 || ecomShipmentCount > 1,
147+
[omsShipmentCount, ecomShipmentCount]
144148
)
145149

150+
const showMultiShipmentsFromOmsOnly = isOmsOrder && hasOmsShipment && isMultiShipmentOrder
151+
146152
const {pickupShipments, deliveryShipments} = useMemo(() => {
147153
return storeLocatorEnabled
148154
? groupShipmentsByDeliveryOption(order)
@@ -396,14 +402,14 @@ const AccountOrderDetail = () => {
396402
)
397403
})}
398404
{/* Any type of Non-OMS or any type of single shipment order: show DeliveryMethods and Shipments info*/}
399-
{(!isOmsOrder || !isMultiShipmentOrder) &&
405+
{!showMultiShipmentsFromOmsOnly &&
400406
deliveryShipments.map((shipment, index) => {
401407
const omsShipment = isOmsOrder
402408
? order.omsData.shipments?.[index]
403409
: null
404410

405411
const shippingMethodName =
406-
omsShipment?.provider || shipment.shippingMethod.name
412+
omsShipment?.provider || shipment.shippingMethod?.name
407413
const shippingStatus =
408414
omsShipment?.status || shipment.shippingStatus
409415
const trackingNumber =
@@ -457,16 +463,15 @@ const AccountOrderDetail = () => {
457463
})}
458464

459465
{/* Any OMS multi-shipment: Only show OMS Shipments info;*/}
460-
{isOmsOrder &&
461-
isMultiShipmentOrder &&
466+
{showMultiShipmentsFromOmsOnly &&
462467
order?.omsData?.shipments?.map((shipment, index) => (
463468
<React.Fragment key={`oms-shipment-${index}`}>
464469
{renderShippingMethod(
465470
shipment.provider,
466471
shipment.status,
467472
shipment.trackingNumber,
468473
shipment.trackingUrl,
469-
order?.omsData?.shipments?.length ?? 0,
474+
omsShipmentCount,
470475
index
471476
)}
472477
</React.Fragment>

packages/template-retail-react-app/app/pages/account/orders.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,3 +1388,58 @@ describe('BOPIS Order - ECOM Only (No OMS)', () => {
13881388
expect(screen.queryByRole('heading', {name: /shipping address/i})).not.toBeInTheDocument()
13891389
})
13901390
})
1391+
1392+
describe('OMS order with no OMS shipments - default to ECOM shipment display (multi-ship)', () => {
1393+
// Multi-shipment scenario: OMS order has omsData but no OMS shipments.
1394+
const omsOrderMultiShipNoOmsShipments = createMockOmsOrder({
1395+
omsData: {
1396+
status: 'Created'
1397+
},
1398+
shipments: [
1399+
{
1400+
shipmentId: 'ship1',
1401+
shippingMethod: {name: 'Ground'},
1402+
shippingAddress: {
1403+
fullName: 'Alex Johnson',
1404+
address1: '876 NE 8th st',
1405+
city: 'Seattle',
1406+
stateCode: 'WA',
1407+
postalCode: '98121',
1408+
countryCode: 'US'
1409+
}
1410+
},
1411+
{
1412+
shipmentId: 'ship2',
1413+
shippingMethod: {name: 'Express'},
1414+
shippingAddress: {
1415+
fullName: 'Bob Smith',
1416+
address1: '456 Second St',
1417+
city: 'Portland',
1418+
stateCode: 'OR',
1419+
postalCode: '97201',
1420+
countryCode: 'US'
1421+
}
1422+
}
1423+
]
1424+
})
1425+
1426+
test('should display multi-shipment Shipping Method and Shipping Address from ECOM when OMS has no shipments', async () => {
1427+
setupOrderDetailsPage(omsOrderMultiShipNoOmsShipments)
1428+
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
1429+
// Default to ECOM delivery block (multi-shipment) when OMS has no shipments.
1430+
expect(await screen.findByRole('heading', {name: /shipping method 1/i})).toBeInTheDocument()
1431+
expect(await screen.findByRole('heading', {name: /shipping method 2/i})).toBeInTheDocument()
1432+
expect(
1433+
await screen.findByRole('heading', {name: /shipping address 1/i})
1434+
).toBeInTheDocument()
1435+
expect(
1436+
await screen.findByRole('heading', {name: /shipping address 2/i})
1437+
).toBeInTheDocument()
1438+
expect(await screen.findByText(/Alex Johnson/i)).toBeInTheDocument()
1439+
expect(await screen.findByText(/Bob Smith/i)).toBeInTheDocument()
1440+
expect(await screen.findByText(/876 NE 8th st/i)).toBeInTheDocument()
1441+
expect(await screen.findByText(/456 Second St/i)).toBeInTheDocument()
1442+
expect(await screen.findByText(/Ground/i)).toBeInTheDocument()
1443+
expect(await screen.findByText(/Express/i)).toBeInTheDocument()
1444+
})
1445+
})

0 commit comments

Comments
 (0)