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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixes when having multiple custom options with overlapping option_type_id values, selecting 1 changes the others - @carlokok (#4196)
- Update eslint and fix code style. - @gibkigonzo (#4179 #4181)
- Fixes bug that caused addToCart action not to display messages to user - @juho-jaakkola (#4185)
- add missing cache tags for category and product - @gibkigonzo (#4173)
- add ssrAppId to avoid second meta render on csr - @gibkigonzo (#4203)

Expand Down
2 changes: 1 addition & 1 deletion core/modules/cart/store/actions/connectActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const connectActions = {
const cartToken = getters['getCartToken']
if (storedItems.length && !cartToken) {
Logger.info('Creating server cart token', 'cart')()
await dispatch('connect', { guestCart: false })
return dispatch('connect', { guestCart: false })
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions core/modules/cart/store/actions/itemActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,18 @@ const itemActions = {
productIndex++
}
}
await dispatch('create')

let newDiffLog = await dispatch('create')
if (newDiffLog !== undefined) {
diffLog.merge(newDiffLog)
}

if (getters.isCartSyncEnabled && getters.isCartConnected && !forceServerSilence) {
return dispatch('sync', { forceClientState: true })
const syncDiffLog = await dispatch('sync', { forceClientState: true })

if (!syncDiffLog.isEmpty()) {
diffLog.merge(syncDiffLog)
Copy link
Author

@juho-jaakkola juho-jaakkola Mar 23, 2020

Choose a reason for hiding this comment

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

Make sure that all these .merge() calls make sense, as I'm not that familiar with the cart implementation.

}
}

return diffLog
Expand Down
10 changes: 8 additions & 2 deletions core/modules/cart/test/unit/store/itemActions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ jest.mock('@vue-storefront/core/modules/cart/helpers', () => ({
createNotifications: jest.fn()
},
createDiffLog: () => ({
pushNotifications: jest.fn()
pushNotifications: jest.fn(),
merge: jest.fn()
})
}));
jest.mock('@vue-storefront/core/helpers', () => ({
Expand Down Expand Up @@ -140,7 +141,12 @@ describe('Cart itemActions', () => {
}
})

contextMock.dispatch.mockImplementationOnce(() => Promise.resolve({ status: 'ok', onlineCheckTaskId: 1 }))
// The third 'dispatch' call gets an instance of DiffLog class, which has the isEmpty() method.
// The return value of the second 'dispatch' call is not used at all, so it can be left empty.
contextMock.dispatch
.mockImplementationOnce(() => Promise.resolve({ status: 'ok', onlineCheckTaskId: 1 }))
.mockImplementationOnce(() => Promise.resolve({}))
.mockImplementationOnce(() => Promise.resolve({ isEmpty: () => { return true } }))

await (cartActions as any).addItems(contextMock, { productsToAdd: [product] })
expect(contextMock.commit).toBeCalledWith(types.CART_ADD_ITEM, { product: { ...product, onlineStockCheckid: 1 } })
Expand Down