11<template >
2- <template v-if =" allCategoryProducts ?.productCategory ?.products ?.nodes " >
3- <section >
4- <div id =" product-container" class =" flex flex-wrap items-center" >
5- <template
6- v-for =" product in allCategoryProducts .productCategory .products .nodes "
2+ <div id =" product-container" class =" flex flex-wrap items-center" >
3+ <template v-for =" product in products " :key =" product .id " >
4+ <div class =" flex flex-col mt-6 sm:w-1/2 md:w-1/3 lg:w-1/4 lg:mr-4" >
5+ <NuxtLink
6+ class =" text-black cursor-pointer hover:underline"
7+ :to =" productLink(product)"
78 >
8- <div
9- v-if =" product.slug"
10- :key =" product.id"
11- class =" flex flex-col mt-6 sm:w1/2 md:w-1/3 lg:w-1/4 lg:mr-4"
12- >
13- <NuxtLink
14- class =" text-black cursor-pointer hover:underline"
15- :to =" {
16- path: '/product/' + product.slug,
17- query: { id: product.databaseId },
18- }"
19- >
20- <ProductImage :alt =" product.name" :src =" productImage(product)" />
21-
22- <div class =" flex justify-center pt-3" >
23- <p class =" text-2xl font-bold text-center cursor-pointer" >
24- {{ product.name }}
25- </p >
26- </div >
27- </NuxtLink >
28- <ProductPrice
29- :product =" product"
30- priceFontSize =" normal"
31- :shouldCenterPrice =" true"
32- />
33- </div >
34- </template >
35- </div >
36- </section >
37- </template >
38- <div v-else >
39- <section >
40- <div id =" product-container" class =" flex flex-wrap items-center" >
41- <template v-for =" product in allProducts .products .nodes " >
42- <div
43- v-if =" product.slug"
44- :key =" product.id"
45- class =" flex flex-col mt-6 sm:w1/2 md:w-1/3 lg:w-1/4 lg:mr-4"
46- >
47- <NuxtLink
48- class =" text-black cursor-pointer hover:underline"
49- :to =" {
50- path: '/product/' + product.slug,
51- query: { id: product.databaseId },
52- }"
53- >
54- <ProductImage :alt =" product.name" :src =" productImage(product)" />
55- <div class =" flex justify-center pt-3" >
56- <p class =" text-2xl font-bold text-center cursor-pointer" >
57- {{ product.name }}
58- </p >
59- </div >
60- </NuxtLink >
61- <ProductPrice
62- :product =" product"
63- priceFontSize =" normal"
64- :shouldCenterPrice =" true"
65- />
9+ <ProductImage :alt =" product.name" :src =" productImage(product)" />
10+ <div class =" flex justify-center pt-3" >
11+ <p class =" text-2xl font-bold text-center cursor-pointer" >
12+ {{ product.name }}
13+ </p >
6614 </div >
67- </template >
15+ </NuxtLink >
16+ <ProductPrice
17+ :product =" product"
18+ priceFontSize =" normal"
19+ :shouldCenterPrice =" true"
20+ />
6821 </div >
69- </section >
22+ </template >
7023 </div >
7124</template >
7225
@@ -84,6 +37,35 @@ const props = defineProps({
8437
8538const config = useRuntimeConfig ();
8639
40+ const products = computed (() => {
41+ return (
42+ allCategoryProducts .value ? .productCategory ? .products ? .nodes ||
43+ allProducts .value ? .products ? .nodes ||
44+ []
45+ );
46+ });
47+
48+ /**
49+ * Returns the path and query parameters for a product link.
50+ *
51+ * @param {Object} product - Object containing product information.
52+ * @param {string} product.slug - The product's URL slug.
53+ * @param {number} product.databaseId - The product's database ID.
54+ * @return {Object} An object containing the product's path and query parameters.
55+ */
56+ const productLink = (product ) => {
57+ return {
58+ path: " /product/" + product .slug ,
59+ query: { id: product .databaseId },
60+ };
61+ };
62+
63+ /**
64+ * Returns the source URL of a product image or a placeholder image if the product does not have an image.
65+ *
66+ * @param {Object} product - The product object containing the image source URL.
67+ * @return {string} The source URL of the product image or a placeholder image if the product does not have an image.
68+ */
8769const productImage = (product ) =>
8870 product .image ? product .image .sourceUrl : config .public .placeholderImage ;
8971
0 commit comments