1
1
<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)"
7
8
>
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
- <div class =" flex justify-center pt-3" >
22
- <p class =" text-2xl font-bold text-center cursor-pointer" >
23
- {{ product.name }}
24
- </p >
25
- </div >
26
- </NuxtLink >
27
- <ProductPrice
28
- :product =" product"
29
- priceFontSize =" normal"
30
- :shouldCenterPrice =" true"
31
- />
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 >
32
14
</div >
33
- </template >
15
+ </NuxtLink >
16
+ <ProductPrice
17
+ :product =" product"
18
+ priceFontSize =" normal"
19
+ :shouldCenterPrice =" true"
20
+ />
34
21
</div >
35
- </section >
36
- </template >
37
- <div v-else >
38
- <section >
39
- <div id =" product-container" class =" flex flex-wrap items-center" >
40
- <template v-for =" product in allProducts .products .nodes " >
41
- <div
42
- v-if =" product.slug"
43
- :key =" product.id"
44
- class =" flex flex-col mt-6 sm:w1/2 md:w-1/3 lg:w-1/4 lg:mr-4"
45
- >
46
- <NuxtLink
47
- class =" text-black cursor-pointer hover:underline"
48
- :to =" {
49
- path: '/product/' + product.slug,
50
- query: { id: product.databaseId },
51
- }"
52
- >
53
- <ProductImage :alt =" product.name" :src =" productImage(product)" />
54
- <div class =" flex justify-center pt-3" >
55
- <p class =" text-2xl font-bold text-center cursor-pointer" >
56
- {{ product.name }}
57
- </p >
58
- </div >
59
- </NuxtLink >
60
- <ProductPrice
61
- :product =" product"
62
- priceFontSize =" normal"
63
- :shouldCenterPrice =" true"
64
- />
65
- </div >
66
- </template >
67
- </div >
68
- </section >
22
+ </template >
69
23
</div >
70
24
</template >
71
25
@@ -83,6 +37,29 @@ const props = defineProps({
83
37
84
38
const config = useRuntimeConfig ();
85
39
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
+
86
63
/**
87
64
* Returns the source URL of a product image or a placeholder image if the product does not have an image.
88
65
*
0 commit comments