Skip to content

Commit 34b3f2c

Browse files
committed
Fix category product display
1 parent b89b702 commit 34b3f2c

File tree

1 file changed

+62
-10
lines changed

1 file changed

+62
-10
lines changed

components/Products/ProductsShowAll.vue

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,62 @@
11
<template>
2-
<div v-if="data?.products?.nodes">
2+
<div v-if="allCategoryProducts?.productCategory?.products?.nodes">
33
<section>
44
<div id="product-container" class="flex flex-wrap items-center">
5-
<template v-for="product in data.products.nodes">
5+
<template
6+
v-for="product in allCategoryProducts.productCategory.products.nodes"
7+
>
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+
<img
21+
id="product-image"
22+
class="p-8 border mx-auto w-4/5 border-gray-200 lg:h-[230px] rounded drop-shadow-lg transition duration-500 ease-in-out transform cursor-pointer lg:ml-0 lg:w-full lg:p-2 hover:scale-95"
23+
:alt="product.name"
24+
:src="productImage(product)"
25+
/>
26+
<div class="flex justify-center pt-3">
27+
<p class="text-2xl font-bold text-center cursor-pointer">
28+
{{ product.name }}
29+
</p>
30+
</div>
31+
</NuxtLink>
32+
<div v-if="product.onSale" class="flex justify-center mt-2">
33+
<div class="text-lg text-gray-900 line-through">
34+
<span v-if="product.variations">
35+
{{ filteredVariantPrice(product.price, "right") }}</span
36+
>
37+
<span v-else>{{ product.regularPrice }}</span>
38+
</div>
39+
<div class="ml-4 text-xl text-gray-900">
40+
<span v-if="product.variations">
41+
{{ filteredVariantPrice(product.price) }}</span
42+
>
43+
<span v-else>{{ product.salePrice }}</span>
44+
</div>
45+
</div>
46+
<div v-else>
47+
<p class="mt-2 text-xl text-center text-gray-900">
48+
{{ product.price }}
49+
</p>
50+
</div>
51+
</div>
52+
</template>
53+
</div>
54+
</section>
55+
</div>
56+
<div v-else>
57+
<section>
58+
<div id="product-container" class="flex flex-wrap items-center">
59+
<template v-for="product in allProducts.products.nodes">
660
<div
761
v-if="product.slug"
862
:key="product.id"
@@ -70,18 +124,16 @@ const productImage = (product) =>
70124
product.image ? product.image.sourceUrl : config.placeholderImage;
71125
72126
const productVariables = { limit: 99 };
73-
const { data } = await useAsyncQuery(
127+
const { data: allProducts } = await useAsyncQuery(
74128
FETCH_ALL_PRODUCTS_QUERY,
75129
productVariables
76130
);
77131
78-
if (props.id) {
79-
const categoryVariables = { id: props.categoryId, slug: props.categorySlug };
80-
const { data } = await useAsyncQuery(
81-
GET_PRODUCTS_FROM_CATEGORY_QUERY,
82-
categoryVariables
83-
);
84-
}
132+
const categoryVariables = { id: props.categoryId };
133+
const { data: allCategoryProducts } = await useAsyncQuery(
134+
GET_PRODUCTS_FROM_CATEGORY_QUERY,
135+
categoryVariables
136+
);
85137
</script>
86138

87139
<style scoped>

0 commit comments

Comments
 (0)