diff --git a/packages/theme/modules/customer/pages/MyAccount/MyWishlist.vue b/packages/theme/modules/customer/pages/MyAccount/MyWishlist.vue index e64e5dbf1..7ba0879a7 100644 --- a/packages/theme/modules/customer/pages/MyAccount/MyWishlist.vue +++ b/packages/theme/modules/customer/pages/MyAccount/MyWishlist.vue @@ -252,16 +252,17 @@ import { import { computed, defineComponent, + onMounted, useRouter, useRoute, useContext, - useAsync, } from '@nuxtjs/composition-api'; import productGetters from '~/modules/catalog/product/getters/productGetters'; import type { Product } from '~/modules/catalog/product/types'; import { useWishlist } from '~/modules/wishlist/composables/useWishlist'; import wishlistGetters from '~/modules/wishlist/getters/wishlistGetters'; import { useCart } from '~/modules/checkout/composables/useCart'; +import { useWishlistStore } from '~/modules/wishlist/store/wishlistStore'; import { useUiHelpers, @@ -297,19 +298,10 @@ export default defineComponent({ const th = useUiHelpers(); const uiState = useUiState(); const { addItem: addItemToCartBase, isInCart } = useCart(); - const wishlist = useAsync(async () => { - const wishlistData = await load({ - searchParams: { - currentPage: page ? Number.parseInt(page.toString(), 10) : 1, - pageSize: itemsPerPage ? Number.parseInt(itemsPerPage.toString(), 10) : 10, - }, - }); - - return wishlistData; - }); + const wishlistStore = useWishlistStore(); - const products = computed(() => wishlistGetters.getProducts(wishlist?.value)); - const pagination = computed(() => wishlistGetters.getPagination(wishlist?.value?.[0])); + const products = computed(() => wishlistGetters.getProducts(wishlistStore.wishlist)); + const pagination = computed(() => wishlistGetters.getPagination(wishlistStore.wishlist)); const addItemToCart = async ({ product, quantity }: { product: Product, quantity: number }) => { // eslint-disable-next-line no-underscore-dangle @@ -342,6 +334,15 @@ export default defineComponent({ const { getMagentoImage, imageSizes } = useImage(); + onMounted(async () => { + await load({ + searchParams: { + currentPage: page ? Number.parseInt(page.toString(), 10) : 1, + pageSize: itemsPerPage ? Number.parseInt(itemsPerPage.toString(), 10) : 10, + }, + }); + }); + return { ...uiState, addItemToCart, @@ -352,7 +353,6 @@ export default defineComponent({ productGetters, products, th, - wishlist, getMagentoImage, imageSizes, }; diff --git a/packages/theme/modules/wishlist/composables/useWishlist/index.ts b/packages/theme/modules/wishlist/composables/useWishlist/index.ts index 945472e5d..562c9de1c 100644 --- a/packages/theme/modules/wishlist/composables/useWishlist/index.ts +++ b/packages/theme/modules/wishlist/composables/useWishlist/index.ts @@ -117,7 +117,7 @@ export function useWishlist(): UseWishlistInterface { const loadedWishlist = data?.customer?.wishlists ?? []; itemsCount = calculateWishlistTotal(loadedWishlist); wishlistStore.$patch((state) => { - state.wishlist = { items_count: itemsCount }; + state.wishlist.items_count = itemsCount; }); } } catch (err) {