@@ -19,9 +19,6 @@ const SingleProduct = ({ product }) => {
1919 setIsLoading ( false ) ;
2020 } , [ ] ) ;
2121
22- //console.log("Product information: ");
23- //console.log(product);
24-
2522 const {
2623 description,
2724 image,
@@ -77,20 +74,21 @@ const SingleProduct = ({ product }) => {
7774 < p className = "pt-1 mt-4 text-2xl text-gray-900" >
7875 { DESCRIPTION_WITHOUT_HTML }
7976 </ p >
80-
8177 { product . variations && (
8278 < p className = "pt-1 mt-4 text-xl text-gray-900" >
8379 < span className = "py-2" > Varianter</ span >
8480 < select
8581 id = "variant"
8682 name = "variant"
8783 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+ } }
8987 >
9088 { product . variations . nodes . map (
9189 ( { id, name, variationId } ) => {
90+ // Remove product name from variation name
9291 const filteredName = name . split ( '- ' ) . pop ( ) ;
93-
9492 return (
9593 < option key = { id } value = { variationId } >
9694 { filteredName }
@@ -101,10 +99,15 @@ const SingleProduct = ({ product }) => {
10199 </ select >
102100 </ p >
103101 ) }
104-
105102 < 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+ ) }
108111 </ div >
109112 </ div >
110113 </ div >
0 commit comments