Skip to content

Commit

Permalink
#4083 & #3838 Bugfix for cart-tab-sync in multistore environment
Browse files Browse the repository at this point in the history
  • Loading branch information
cewald committed Apr 6, 2021
1 parent a8fdea4 commit 7696efc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/modules/cart/helpers/syncCartWhenLocalStorageChange.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
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 }) {
const value = JSON.parse(localStorage[key])
if (key === 'shop/cart/current-cart') {
if (checkMultistoreKey(key, 'shop/cart/current-cart')) {
rootStore.dispatch('cart/updateCart', { items: value })
} else if (key === 'shop/cart/current-totals') {
} else if (checkMultistoreKey(key, 'shop/cart/current-totals')) {
rootStore.dispatch('cart/updateTotals', value)
}
}

function checkMultistoreKey (key: string, path: string): boolean {
const { multistore, commonCache } = storeViews
if (!multistore || (multistore && commonCache)) return key === path
return key === `${currentStoreView().storeCode}-${path}`
}

function addEventListener () {
window.addEventListener('storage', getItemsFromStorage)
}
Expand Down

0 comments on commit 7696efc

Please sign in to comment.