Skip to content

Commit db85985

Browse files
@W-19442561 - Fix Incorrectly Disabled Continue to Shipping Method Button for Multiship (#3199)
1 parent 60d9a47 commit db85985

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- Add support for environment level base paths on /mobify routes [#2892](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2892)
33
- Fix private client endpoint prop name [#3177](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3177)
44
- This feature introduces an AI-powered shopping assistant that integrates Salesforce Embedded Messaging Service with PWA Kit applications. The shopper agent provides real-time chat support, search assistance, and personalized shopping guidance directly within the e-commerce experience. [#2658](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2658)
5-
- Added support for Multi-Ship [#3056](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3056)
5+
- Added support for Multi-Ship [#3056](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3056) [#3199] (https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3199)
66
- The feature toggle for partial hydration is now found in the config file (`config.app.partialHydrationEnabled`) [#3058](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3058)
77
- Mask user not found messages to prevent user enumeration from passwordless login [#3113](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3113)
88
- [Bugfix] Pin `@chakra-ui/react` version to 2.7.0 to avoid breaking changes from 2.10.9 [#2658](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2658)

packages/template-retail-react-app/app/hooks/use-product-address-assignment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ export const useProductAddressAssignment = (basket) => {
143143
const shipment = existingShipments.find((s) => s.shipmentId === item.shipmentId)
144144

145145
if (shipment && !isAddressEmpty(shipment.shippingAddress)) {
146-
const existingAddress = guestAddresses.find((addr) =>
147-
areAddressesEqual(addr, shipment.shippingAddress)
146+
const existingAddress = [...guestAddresses, ...newGuestAddresses].find(
147+
(addr) => areAddressesEqual(addr, shipment.shippingAddress)
148148
)
149149

150150
if (existingAddress) {

packages/template-retail-react-app/app/hooks/use-product-address-assignment.test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,60 @@ describe('useProductAddressAssignment', () => {
249249

250250
expect(result.current.availableAddresses).toHaveLength(initialAddressCount)
251251
})
252+
253+
test('should reuse same address for multiple items with identical shipping address', () => {
254+
mockUseCurrentCustomer.mockReturnValue({
255+
data: mockGuestCustomer,
256+
isLoading: false
257+
})
258+
259+
// Create a basket where both items are in the same shipment
260+
const basketWithSameAddress = {
261+
basketId: 'basket-1',
262+
productItems: [
263+
{itemId: 'item-1', productId: 'product-1', shipmentId: 'shipment-1'},
264+
{itemId: 'item-2', productId: 'product-2', shipmentId: 'shipment-1'}
265+
],
266+
shipments: [
267+
{
268+
shipmentId: 'shipment-1',
269+
shippingMethod: {id: 'delivery-method-1'},
270+
shippingAddress: {
271+
firstName: 'John',
272+
lastName: 'Doe',
273+
address1: '123 Main St',
274+
city: 'San Francisco',
275+
stateCode: 'CA',
276+
postalCode: '94105',
277+
countryCode: 'US',
278+
phone: '4155551234'
279+
}
280+
}
281+
]
282+
}
283+
284+
const {result} = renderHook(() => useProductAddressAssignment(basketWithSameAddress))
285+
286+
// Should create only one address entry for both items
287+
expect(result.current.availableAddresses).toHaveLength(1)
288+
289+
// Both items should reference the same address ID
290+
const addressId1 = result.current.selectedAddresses['item-1']
291+
const addressId2 = result.current.selectedAddresses['item-2']
292+
293+
expect(addressId1).toBeDefined()
294+
expect(addressId2).toBeDefined()
295+
expect(addressId1).toBe(addressId2)
296+
297+
// The address should match what was in the shipment
298+
const address = result.current.availableAddresses[0]
299+
expect(address.firstName).toBe('John')
300+
expect(address.lastName).toBe('Doe')
301+
expect(address.address1).toBe('123 Main St')
302+
303+
// All items should have addresses (button should be enabled)
304+
expect(result.current.allItemsHaveAddresses).toBe(true)
305+
})
252306
})
253307

254308
describe('addGuestAddress', () => {

packages/template-retail-react-app/app/utils/shipment-utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
import {
99
cleanAddressForOrder,
10-
areAddressesEqual,
11-
isAddressEmpty
10+
areAddressesEqual
1211
} from '@salesforce/retail-react-app/app/utils/address-utils'
1312
import {DEFAULT_SHIPMENT_ID} from '@salesforce/retail-react-app/app/constants'
1413

0 commit comments

Comments
 (0)