1
1
<template >
2
2
<div class =" product-single-container" >
3
- <template v-if =" data ?. product " >
3
+ <template v-if =" product " >
4
4
<section >
5
5
<div class =" container flex flex-wrap items-center pt-4 pb-12 mx-auto" >
6
6
<div
7
7
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"
8
8
>
9
- <ProductsImage
10
- :alt =" data.product.name"
11
- :src =" data.product.image.sourceUrl"
12
- />
9
+ <ProductsImage :alt =" product.name" :src =" product.image.sourceUrl" />
13
10
<div class =" ml-8" >
14
11
<p class =" text-3xl font-bold text-left" >
15
- {{ data. product.name }}
12
+ {{ product.name }}
16
13
</p >
17
14
<ProductsPrice
18
- :product =" data. product"
15
+ :product =" product"
19
16
:shouldCenterPrice =" false"
20
17
priceFontSize =" big"
21
18
/>
22
19
<p class =" pt-1 mt-6 text-2xl text-gray-900" >
23
- {{ stripHTML(data. product.description) }}
20
+ {{ stripHTML(product.description) }}
24
21
</p >
25
22
<p
26
- v-if =" data. product.stockQuantity"
23
+ v-if =" product.stockQuantity"
27
24
class =" pt-1 mt-4 text-2xl text-gray-900"
28
25
>
29
- {{ data. product.stockQuantity }} in stock
26
+ {{ product.stockQuantity }} in stock
30
27
</p >
31
28
<p
32
- v-if =" data. product.variations"
29
+ v-if =" product.variations"
33
30
class =" pt-1 mt-4 text-xl text-gray-900"
34
31
>
35
32
<span class =" py-2" >Varianter</span >
40
37
v-model =" selectedVariation"
41
38
>
42
39
<option
43
- v-for =" (variation, index) in data. product.variations.nodes"
40
+ v-for =" (variation, index) in product.variations.nodes"
44
41
:key =" variation.databaseId"
45
42
:value =" variation.databaseId"
46
43
:selected =" index === 0"
47
44
>
48
- {{ filteredVariantName(data. product.name, variation.name) }}
45
+ {{ filteredVariantName(product.name, variation.name) }}
49
46
({{ variation.stockQuantity }} in stock)
50
47
</option >
51
48
</select >
52
49
</p >
53
50
<div class =" pt-1 mt-2" >
54
51
<CommonButton
55
- @common-button-click =" addProductToCart(data. product)"
52
+ @common-button-click =" addProductToCart(product)"
56
53
:is-loading =" isLoading"
57
54
>
58
55
ADD TO CART
80
77
81
78
import { ref , watch , computed } from " vue" ;
82
79
83
- import GET_SINGLE_PRODUCT_QUERY from " @/apollo/queries/GET_SINGLE_PRODUCT_QUERY.gql" ;
84
-
85
80
import { stripHTML , filteredVariantName } from " @/utils/functions" ;
86
81
87
82
import { useCart } from " @/store/useCart" ;
@@ -90,23 +85,19 @@ const cart = useCart();
90
85
91
86
const isLoading = computed (() => cart .loading );
92
87
93
- const selectedVariation = ref (); // TODO Pass this value to addProductToCart()
94
88
const toast = ref (null );
95
89
96
90
const props = defineProps ({
97
- id: { type: String , required: true },
98
- slug: { type: String , required: true },
91
+ product: { type: Object , required: true },
99
92
});
100
93
101
- const variables = { id: props .id , slug: props .slug };
102
- const { data } = await useAsyncQuery (GET_SINGLE_PRODUCT_QUERY , variables);
94
+ const selectedVariation = ref ();
103
95
104
96
watch (
105
- () => data .value ,
106
- (dataValue ) => {
107
- if (dataValue && dataValue .product ? .variations ? .nodes ? .length > 0 ) {
108
- selectedVariation .value =
109
- dataValue .product ? .variations ? .nodes [0 ].databaseId ;
97
+ () => props .product ,
98
+ (productValue ) => {
99
+ if (productValue && productValue .variations ? .nodes ? .length > 0 ) {
100
+ selectedVariation .value = productValue .variations ? .nodes [0 ].databaseId ;
110
101
}
111
102
},
112
103
{ immediate: true }
0 commit comments