Skip to content

Commit ce23de4

Browse files
authored
Merge pull request #5732 from icmaa/bugfix/multi-tab-cart-sync-in-multistore
Bugfix for cart-tab-sync in multistore environment
2 parents 75d7e1b + 7769761 commit ce23de4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939
- servercart-after-diff event payload - Fifciu (#5365)
4040
- Fix Original Price Calculation typo - @akucharczyk / @lukaszjedrasik (#5472)
4141
- Purge loader works properly with dynamic config reload - @Fifciu
42+
- Multi-tab cart-sync in multi-store environment - @cewald (#5711, #5732)
4243

4344
### Changed / Improved
4445

core/modules/cart/helpers/syncCartWhenLocalStorageChange.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import rootStore from '@vue-storefront/core/store';
1+
import rootStore from '@vue-storefront/core/store'
2+
import { storeViews } from 'config'
3+
import { currentStoreView } from '@vue-storefront/core/lib/multistore'
4+
5+
function checkMultistoreKey (key: string, path: string): boolean {
6+
const { multistore, commonCache } = storeViews
7+
if (!multistore || (multistore && commonCache)) return key === path
8+
return key === `${currentStoreView().storeCode}-${path}`
9+
}
210

311
function getItemsFromStorage ({ key }) {
4-
const value = JSON.parse(localStorage[key])
5-
if (key === 'shop/cart/current-cart') {
12+
if (checkMultistoreKey(key, 'shop/cart/current-cart')) {
13+
const value = JSON.parse(localStorage[key])
614
rootStore.dispatch('cart/updateCart', { items: value })
7-
} else if (key === 'shop/cart/current-totals') {
15+
} else if (checkMultistoreKey(key, 'shop/cart/current-totals')) {
16+
const value = JSON.parse(localStorage[key])
817
rootStore.dispatch('cart/updateTotals', value)
918
}
1019
}

0 commit comments

Comments
 (0)