@@ -19,9 +19,6 @@ const SingleProduct = ({ product }) => {
19
19
setIsLoading ( false ) ;
20
20
} , [ ] ) ;
21
21
22
- //console.log("Product information: ");
23
- //console.log(product);
24
-
25
22
const {
26
23
description,
27
24
image,
@@ -77,20 +74,21 @@ const SingleProduct = ({ product }) => {
77
74
< p className = "pt-1 mt-4 text-2xl text-gray-900" >
78
75
{ DESCRIPTION_WITHOUT_HTML }
79
76
</ p >
80
-
81
77
{ product . variations && (
82
78
< p className = "pt-1 mt-4 text-xl text-gray-900" >
83
79
< span className = "py-2" > Varianter</ span >
84
80
< select
85
81
id = "variant"
86
82
name = "variant"
87
83
className = "block w-64 px-6 py-2 bg-white border border-gray-500 rounded-lg focus:outline-none focus:shadow-outline"
88
- onChange = { ( e ) => { setselectedVariation ( e . target . value ) } }
84
+ onChange = { ( e ) => {
85
+ setselectedVariation ( e . target . value ) ;
86
+ } }
89
87
>
90
88
{ product . variations . nodes . map (
91
89
( { id, name, variationId } ) => {
90
+ // Remove product name from variation name
92
91
const filteredName = name . split ( '- ' ) . pop ( ) ;
93
-
94
92
return (
95
93
< option key = { id } value = { variationId } >
96
94
{ filteredName }
@@ -101,10 +99,15 @@ const SingleProduct = ({ product }) => {
101
99
</ select >
102
100
</ p >
103
101
) }
104
-
105
102
< div className = "pt-1 mt-2" >
106
- { ! product . variations && < AddToCartButton product = { product } /> }
107
- { product . variations && < AddToCartButton product = { selectedVariation } /> }
103
+ {
104
+ // Display default AddToCart button if we dont have variations. If we do, send the variationId to AddToCart button
105
+ }
106
+ { product . variations ? (
107
+ < AddToCartButton product = { selectedVariation } />
108
+ ) : (
109
+ < AddToCartButton product = { product } />
110
+ ) }
108
111
</ div >
109
112
</ div >
110
113
</ div >
0 commit comments