|
1 | 1 | <template> |
2 | | - <div v-if="data?.products?.nodes"> |
| 2 | + <div v-if="allCategoryProducts?.productCategory?.products?.nodes"> |
3 | 3 | <section> |
4 | 4 | <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"> |
6 | 60 | <div |
7 | 61 | v-if="product.slug" |
8 | 62 | :key="product.id" |
@@ -70,18 +124,16 @@ const productImage = (product) => |
70 | 124 | product.image ? product.image.sourceUrl : config.placeholderImage; |
71 | 125 |
|
72 | 126 | const productVariables = { limit: 99 }; |
73 | | -const { data } = await useAsyncQuery( |
| 127 | +const { data: allProducts } = await useAsyncQuery( |
74 | 128 | FETCH_ALL_PRODUCTS_QUERY, |
75 | 129 | productVariables |
76 | 130 | ); |
77 | 131 |
|
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 | +); |
85 | 137 | </script> |
86 | 138 |
|
87 | 139 | <style scoped> |
|
0 commit comments