Skip to content

Commit

Permalink
fix: guest user sync (SWF-213)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucmus authored and patzick committed Dec 5, 2022
1 parent e85b0ef commit 57d720a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-zoos-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-pwa/composables-next": patch
---

Avoid wishlist sync for guest session
9 changes: 6 additions & 3 deletions packages/composables/src/useWishlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export type UseWishlistReturn = {
};

export function useWishlist(): UseWishlistReturn {
const { isLoggedIn } = useUser();
const { isLoggedIn, isGuestSession } = useUser();
const canSyncWishlist = computed(
() => isLoggedIn.value && !isGuestSession.value
);
const {
getWishlistProducts: getWishlistProductsLocal,
items: itemsLocal,
Expand All @@ -28,7 +31,7 @@ export function useWishlist(): UseWishlistReturn {
} = useSyncWishlist();

const getWishlistProducts = async () => {
if (isLoggedIn.value) {
if (canSyncWishlist.value) {
await getWishlistProductsSync();
} else {
await getWishlistProductsLocal();
Expand All @@ -48,7 +51,7 @@ export function useWishlist(): UseWishlistReturn {
};

const items = computed(() =>
isLoggedIn.value ? itemsSync.value : itemsLocal.value
canSyncWishlist.value ? itemsSync.value : itemsLocal.value
);
const count = computed(() => items.value.length);

Expand Down

0 comments on commit 57d720a

Please sign in to comment.