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: homepage recommended products #932

Merged
merged 8 commits into from
Jan 8, 2025
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<template>
<RecommendedProducts :products="recommendedProducts"></RecommendedProducts>
<p
v-if="headline"
data-testid="recommended-products-headline"
class="mb-4 typography-text-lg text-center md:text-left"
>
{{ headline }}
</p>

<ProductSlider v-if="recommendedProducts?.length" :items="recommendedProducts" />
</template>

<script setup lang="ts">
Expand Down
1 change: 1 addition & 0 deletions apps/web/components/ProductRecommendedProducts/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type ProductRecommendedProductsProps = {
categoryId: string;
cacheKey?: string;
headline?: string;
};
16 changes: 0 additions & 16 deletions apps/web/components/RecommendedProducts/RecommendedProducts.vue

This file was deleted.

6 changes: 0 additions & 6 deletions apps/web/components/RecommendedProducts/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/web/composables/useHomepage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface UiMediaCardOptions {
alignment?: string;
}

interface ProductRecommendedProductsOptions {
export interface ProductRecommendedProductsOptions {
categoryId: string;
headline?: string;
}
Expand Down
31 changes: 26 additions & 5 deletions apps/web/composables/useHomepage/useHomepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@ export const useHomepage: UseHomepageDataReturn = () => {
}));

const { $i18n } = useNuxtApp();
const currentLocale = ref($i18n.locale.value);

const runtimeConfig = useRuntimeConfig();
const homepageCategoryId = runtimeConfig.public.homepageCategoryId;

const { fetchCategoryTemplate } = useCategoryTemplate();
const { fetchHomepageTemplate } = useFetchHome();

const currentLocale = ref($i18n.locale.value);
const fetchPageTemplate = async (): Promise<void> => {
state.value.loading = true;
const homepageCategoryId = runtimeConfig.public.homepageCategoryId;
const fetchRecommendedProducts = async () => {
state.value.data.blocks.forEach((block) => {
if (block.name === 'ProductRecommendedProducts') {
const options = block.options as ProductRecommendedProductsOptions;
const id = options.categoryId;
const { fetchProductRecommended } = useProductRecommended(id);
fetchProductRecommended(id);
}
});
};

const initializeHomepageTemplate = async () => {
if (typeof homepageCategoryId === 'number') {
await fetchCategoryTemplate(runtimeConfig.public.homepageCategoryId);
await fetchCategoryTemplate(homepageCategoryId);
state.value.data = fetchHomepageTemplate();
if (
(!state.value.data.blocks || state.value.data.blocks.length === 0) &&
Expand All @@ -34,7 +46,16 @@ export const useHomepage: UseHomepageDataReturn = () => {
} else {
state.value.data = useLocaleSpecificHomepageTemplate(currentLocale.value);
}

await fetchRecommendedProducts();
};

const fetchPageTemplate = async (): Promise<void> => {
state.value.loading = true;

await initializeHomepageTemplate();
state.value.dataIsEmpty = !state.value.data.blocks || state.value.data.blocks.length === 0;

state.value.loading = false;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export const useProductRecommended: UseProductRecommendedReturn = (categoryId: s
sort: 'sorting.price.avg_asc',
};

const { data, error } = await useAsyncData(() => useSdk().plentysystems.getFacet(payload));
const { data, error } = await useAsyncData(`useProductRecommended-${categoryId}`, () =>
useSdk().plentysystems.getFacet(payload),
);
useHandleError(error.value);
state.value.data = data?.value?.data?.products ?? state.value.data;
state.value.loading = false;
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/changelog_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Fix for max visible pages on mobile pagination.
- Fix for editor language picker when it showed inverted data template.
- When the media card only displays text, the text block is now left aligned instead of centered.
- The homepage now displays recommended products on initial load.

## v1.8.0 (2024-12-13) <a href="https://github.com/plentymarkets/plentyshop-pwa/compare/v1.7.0...v1.8.0" target="_blank" rel="noopener"><b>Overview of all changes</b></a>

Expand Down
Loading