Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/template-retail-react-app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Integrate Order History page to display data from OMS [#3581](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3581)
- Add shipping display support for OMS [#3588](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3588)
- BOPIS multishipment with OMS [#3613] (https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3613)
- Default to ECOM shipments in case OMS has no shipments [#3639] (https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3639)
- [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)
- Update "Continue Securely" button text to "Continue" for passwordless login [#3556](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3556)
- Util function for passwordless callback URI [#3630](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3630)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,18 @@ const AccountOrderDetail = () => {
// Check if order has OMS data
const isOmsOrder = useMemo(() => !!order?.omsData, [order?.omsData])

// Check if order is multi-shipment order
const omsShipmentCount = order?.omsData?.shipments?.length ?? 0
const ecomShipmentCount = order?.shipments?.length ?? 0

const hasOmsShipment = useMemo(() => omsShipmentCount > 0, [omsShipmentCount])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do the optional chaining at one place? Something like:

const shipmentCount = order?.omsData?.shipments?.length ?? 0;
const hasOmsShipment = useMemo(() => shipmentCount > 0, [shipmentCount]);

const isMultiShipmentOrder = useMemo(
() => (order?.omsData?.shipments?.length ?? 0) > 1 || (order?.shipments?.length ?? 0) > 1,
[isOmsOrder, order?.omsData?.shipments?.length, order?.shipments?.length]
() => omsShipmentCount > 1 || ecomShipmentCount > 1,
[omsShipmentCount, ecomShipmentCount]
)

const showMultiShipmentsFromOmsOnly = isOmsOrder && hasOmsShipment && isMultiShipmentOrder

const {pickupShipments, deliveryShipments} = useMemo(() => {
return storeLocatorEnabled
? groupShipmentsByDeliveryOption(order)
Expand Down Expand Up @@ -396,14 +402,14 @@ const AccountOrderDetail = () => {
)
})}
{/* Any type of Non-OMS or any type of single shipment order: show DeliveryMethods and Shipments info*/}
{(!isOmsOrder || !isMultiShipmentOrder) &&
{!showMultiShipmentsFromOmsOnly &&
deliveryShipments.map((shipment, index) => {
const omsShipment = isOmsOrder
? order.omsData.shipments?.[index]
: null

const shippingMethodName =
omsShipment?.provider || shipment.shippingMethod.name
omsShipment?.provider || shipment.shippingMethod?.name
const shippingStatus =
omsShipment?.status || shipment.shippingStatus
const trackingNumber =
Expand Down Expand Up @@ -457,16 +463,15 @@ const AccountOrderDetail = () => {
})}

{/* Any OMS multi-shipment: Only show OMS Shipments info;*/}
{isOmsOrder &&
isMultiShipmentOrder &&
{showMultiShipmentsFromOmsOnly &&
order?.omsData?.shipments?.map((shipment, index) => (
<React.Fragment key={`oms-shipment-${index}`}>
{renderShippingMethod(
shipment.provider,
shipment.status,
shipment.trackingNumber,
shipment.trackingUrl,
order?.omsData?.shipments?.length ?? 0,
omsShipmentCount,
index
)}
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1388,3 +1388,58 @@ describe('BOPIS Order - ECOM Only (No OMS)', () => {
expect(screen.queryByRole('heading', {name: /shipping address/i})).not.toBeInTheDocument()
})
})

describe('OMS order with no OMS shipments - default to ECOM shipment display (multi-ship)', () => {
// Multi-shipment scenario: OMS order has omsData but no OMS shipments.
const omsOrderMultiShipNoOmsShipments = createMockOmsOrder({
omsData: {
status: 'Created'
},
shipments: [
{
shipmentId: 'ship1',
shippingMethod: {name: 'Ground'},
shippingAddress: {
fullName: 'Alex Johnson',
address1: '876 NE 8th st',
city: 'Seattle',
stateCode: 'WA',
postalCode: '98121',
countryCode: 'US'
}
},
{
shipmentId: 'ship2',
shippingMethod: {name: 'Express'},
shippingAddress: {
fullName: 'Bob Smith',
address1: '456 Second St',
city: 'Portland',
stateCode: 'OR',
postalCode: '97201',
countryCode: 'US'
}
}
]
})

test('should display multi-shipment Shipping Method and Shipping Address from ECOM when OMS has no shipments', async () => {
setupOrderDetailsPage(omsOrderMultiShipNoOmsShipments)
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
// Default to ECOM delivery block (multi-shipment) when OMS has no shipments.
expect(await screen.findByRole('heading', {name: /shipping method 1/i})).toBeInTheDocument()
expect(await screen.findByRole('heading', {name: /shipping method 2/i})).toBeInTheDocument()
expect(
await screen.findByRole('heading', {name: /shipping address 1/i})
).toBeInTheDocument()
expect(
await screen.findByRole('heading', {name: /shipping address 2/i})
).toBeInTheDocument()
expect(await screen.findByText(/Alex Johnson/i)).toBeInTheDocument()
expect(await screen.findByText(/Bob Smith/i)).toBeInTheDocument()
expect(await screen.findByText(/876 NE 8th st/i)).toBeInTheDocument()
expect(await screen.findByText(/456 Second St/i)).toBeInTheDocument()
expect(await screen.findByText(/Ground/i)).toBeInTheDocument()
expect(await screen.findByText(/Express/i)).toBeInTheDocument()
})
})
Loading