|
1 | 1 | <template> |
2 | | - <div v-if="product"> |
| 2 | + <div v-if="data.product"> |
3 | 3 | <section> |
4 | 4 | <div class="container flex flex-wrap items-center pt-4 pb-12 mx-auto"> |
5 | 5 | <div |
6 | 6 | class="grid grid-cols-1 gap-4 mt-8 lg:grid-cols-2 xl:grid-cols-2 md:grid-cols-2 sm:grid-cols-2" |
7 | 7 | > |
8 | 8 | <img |
9 | | - v-if="product.image !== undefined" |
| 9 | + v-if="data.product.image !== undefined" |
10 | 10 | id="product-image" |
11 | 11 | class="h-auto p-8 transition duration-500 ease-in-out transform xl:p-2 md:p-2 lg:p-2 hover:shadow-lg hover:scale-95" |
12 | | - :alt="product.name" |
13 | | - :src="product.image.sourceUrl" |
| 12 | + :alt="data.product.name" |
| 13 | + :src="data.product.image.sourceUrl" |
14 | 14 | /> |
15 | 15 | <img |
16 | 16 | v-else |
17 | 17 | id="product-image" |
18 | 18 | class="h-auto p-8 transition duration-500 ease-in-out transform xl:p-2 md:p-2 lg:p-2 hover:shadow-lg hover:scale-95" |
19 | | - :alt="product.name" |
20 | | - :src="process.env.placeholderSmallImage" |
| 19 | + :alt="data.product.name" |
| 20 | + :src="config.placeholderImage" |
21 | 21 | /> |
22 | 22 | <div class="ml-8"> |
23 | 23 | <p class="text-3xl font-bold text-left"> |
24 | | - {{ product.name }} |
| 24 | + {{ data.product.name }} |
25 | 25 | </p> |
26 | | - <div v-if="product.onSale" class="flex"> |
| 26 | + <div v-if="data.product.onSale" class="flex"> |
27 | 27 | <p class="pt-1 mt-4 text-3xl text-gray-900"> |
28 | | - <span v-if="product.variations"> |
29 | | - {{ filteredVariantPrice(product.price) }}</span |
| 28 | + <span v-if="data.productvariations"> |
| 29 | + {{ filteredVariantPrice(data.product.price) }}</span |
30 | 30 | > |
31 | | - <span v-else>{{ product.salePrice }}</span> |
| 31 | + <span v-else>{{ data.product.salePrice }}</span> |
32 | 32 | </p> |
33 | 33 | <p class="pt-1 pl-8 mt-4 text-2xl text-gray-900 line-through"> |
34 | | - <span v-if="product.variations"> |
35 | | - {{ filteredVariantPrice(product.price, "right") }}</span |
| 34 | + <span v-if="data.productvariations"> |
| 35 | + {{ filteredVariantPrice(data.product.price, "right") }}</span |
36 | 36 | > |
37 | | - <span v-else>{{ product.regularPrice }}</span> |
| 37 | + <span v-else>{{ data.product.regularPrice }}</span> |
38 | 38 | </p> |
39 | 39 | </div> |
40 | 40 | <p v-else class="pt-1 mt-4 text-2xl text-gray-900"> |
41 | | - {{ product.price }} |
| 41 | + {{ data.product.price }} |
42 | 42 | </p> |
43 | 43 | <br /> |
44 | 44 | <p class="pt-1 mt-4 text-2xl text-gray-900"> |
45 | | - {{ stripHTML(product.description) }} |
| 45 | + {{ stripHTML(data.product.description) }} |
46 | 46 | </p> |
47 | 47 | <p |
48 | | - v-if="product.variations" |
| 48 | + v-if="data.product.variations" |
49 | 49 | class="pt-1 mt-4 text-xl text-gray-900" |
50 | 50 | > |
51 | 51 | <span class="py-2">Varianter</span> |
|
55 | 55 | class="block w-64 px-6 py-2 bg-white border border-gray-500 rounded-lg focus:outline-none focus:shadow-outline" |
56 | 56 | > |
57 | 57 | <option |
58 | | - v-for="(variation, index) in product.variations.nodes" |
| 58 | + v-for="(variation, index) in data.product.variations.nodes" |
59 | 59 | :key="variation.databaseId" |
60 | 60 | :value="variation.databaseId" |
61 | 61 | :selected="index === 0" |
|
65 | 65 | </select> |
66 | 66 | </p> |
67 | 67 | <div class="pt-1 mt-2"> |
68 | | - <CartAddToCartButton :product="product" /> |
| 68 | + <CartAddToCartButton :product="data.product" /> |
69 | 69 | </div> |
70 | 70 | </div> |
71 | 71 | </div> |
|
75 | 75 | </template> |
76 | 76 |
|
77 | 77 | <script setup> |
| 78 | +import GET_SINGLE_PRODUCT_QUERY from "@/apollo/queries/GET_SINGLE_PRODUCT_QUERY.gql"; |
| 79 | +
|
78 | 80 | import { stripHTML, filteredVariantPrice } from "@/utils/functions"; |
79 | 81 |
|
80 | | -defineProps({ |
81 | | - product: { |
82 | | - type: [Object], |
83 | | - required: true, |
84 | | - }, |
| 82 | +const config = useRuntimeConfig(); |
| 83 | +
|
| 84 | +const props = defineProps({ |
| 85 | + id: { type: String, required: true }, |
| 86 | + slug: { type: String, required: true }, |
85 | 87 | }); |
| 88 | +
|
| 89 | +const variables = { id: props.id, slug: props.slug }; |
| 90 | +const { data } = await useAsyncQuery(GET_SINGLE_PRODUCT_QUERY, variables); |
86 | 91 | </script> |
0 commit comments