Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-tab cart-sync in multi-store environment #5711

Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changing email & password at once - @Fifciu ([#5315](https://github.com/vuestorefront/vue-storefront/issues/5315))
- Improved: the code to remove the page key from the query before applying a filter - @ymaheshwari1 ([VSF Capybara #561](https://github.com/vuestorefront/vsf-capybara/issues/561))
- Changing regex responsible for UnicodeAlpha validation and added unit tests - @lukaszjedrasik ([#5340](https://github.com/vuestorefront/vue-storefront/issues/5340))
- Multi-tab cart-sync in multi-store environment - @cewald (#5711)

### Changed / Improved

- Add return types for `beforeOutputRendered` response mutator hook in `hooks.ts` - @lsliwaradioluz (#5242)
13 changes: 11 additions & 2 deletions core/modules/cart/helpers/syncCartWhenLocalStorageChange.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import rootStore from '@vue-storefront/core/store';
import rootStore from '@vue-storefront/core/store'
import { storeViews } from 'config'
import { currentStoreView } from '@vue-storefront/core/lib/multistore'

function getItemsFromStorage ({ key }) {
if (key === 'shop/cart/current-cart') {
if (
key === 'shop/cart/current-cart' ||
(
storeViews.multistore &&
!storeViews.commonCache &&
key === `${currentStoreView().storeCode}-shop/cart/current-cart`
)
) {
const storedItems = JSON.parse(localStorage[key])
rootStore.dispatch('cart/syncCartWhenLocalStorageChange', { items: storedItems })
}