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

fix: fixed errors during wishlist loading #995

Merged
Show file tree
Hide file tree
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
28 changes: 14 additions & 14 deletions packages/theme/modules/customer/pages/MyAccount/MyWishlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -352,7 +353,6 @@ export default defineComponent({
productGetters,
products,
th,
wishlist,
getMagentoImage,
imageSizes,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down