Skip to content

Commit f981b37

Browse files
authored
Merge pull request #193 from w3bdesign/development
Remove item from TODO list
2 parents b2543e3 + fbcd44f commit f981b37

File tree

4 files changed

+68
-34
lines changed

4 files changed

+68
-34
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
## TODO
4545

46-
- Make search results from Algolia clickable
4746
- Add support for variable products / product variations
4847
- Hide products not in stock
4948
- Add better SEO

components/Cart/AddToCartButton.component.jsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ import LoadingSpinner from 'components/LoadingSpinner/LoadingSpinner.component';
99

1010
import { GET_CART } from 'utils/const/GQL_QUERIES';
1111
import { ADD_TO_CART } from 'utils/const/GQL_MUTATIONS';
12-
import { WOO_CONFIG } from 'utils/config/nextConfig';
1312

14-
import {
15-
getFormattedCart,
16-
getUpdatedItems,
17-
removeItemFromCart,
18-
} from 'utils/functions/functions';
13+
import { getFormattedCart } from 'utils/functions/functions';
1914

2015
/**
2116
* Display and process product object when we click on the Add To Cart button
@@ -25,14 +20,17 @@ import {
2520
const AddToCartButton = (props) => {
2621
const [cart, setCart] = useContext(AppContext);
2722
const [requestError, setRequestError] = useState(null);
28-
const [showViewCart, setShowViewCart] = useState(false);
29-
const [showAddToCart, setshowAddToCart] = useState(false);
23+
const [showViewCart, setShowViewCart] = useState(false);
24+
const [showAddToCart, setshowAddToCart] = useState(false);
3025

3126
const product = props.product;
3227

28+
console.log(props);
29+
3330
const productQueryInput = {
3431
clientMutationId: uuidv4(), // Generate a unique id.
35-
productId: product.productId,
32+
//productId: product.productId,
33+
productId: product
3634
};
3735

3836
// Get Cart Data.
@@ -64,8 +62,7 @@ const AddToCartButton = (props) => {
6462
refetch();
6563
// Show View Cart Button
6664
setShowViewCart(true);
67-
setshowAddToCart(true)
68-
65+
setshowAddToCart(true);
6966
},
7067
onError: (error) => {
7168
if (error) {
@@ -86,7 +83,8 @@ const AddToCartButton = (props) => {
8683
<button
8784
onClick={handleAddToCartClick}
8885
className={`px-4 py-2 font-bold bg-white border border-gray-400 border-solid rounded hover:bg-gray-400 ${
89-
addToCartLoading && `animate__animated animate__fadeOutUp`} ${showAddToCart && `animate__animated animate__fadeInDown` }`}
86+
addToCartLoading && `animate__animated animate__fadeOutUp`
87+
} ${showAddToCart && `animate__animated animate__fadeInDown`}`}
9088
>
9189
KJØP
9290
</button>

components/Product/SingleProduct.component.jsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ import LoadingSpinner from 'components/LoadingSpinner/LoadingSpinner.component';
1010
*/
1111
const SingleProduct = ({ product }) => {
1212
const [isLoading, setIsLoading] = useState(true);
13+
// Set first variation as default selected variant
14+
const [selectedVariation, setselectedVariation] = useState(
15+
product.variations.nodes[0].variationId
16+
);
17+
1318
useEffect(() => {
1419
setIsLoading(false);
1520
}, []);
1621

22+
//console.log("Product information: ");
23+
//console.log(product);
24+
1725
const {
1826
description,
1927
image,
@@ -69,28 +77,34 @@ const SingleProduct = ({ product }) => {
6977
<p className="pt-1 mt-4 text-2xl text-gray-900">
7078
{DESCRIPTION_WITHOUT_HTML}
7179
</p>
72-
{/*
73-
<p className="pt-1 mt-4 text-xl text-gray-900">
74-
<span className="py-2">Farge</span>
75-
<select
76-
id="farge"
77-
className="block w-64 px-6 py-2 bg-white border border-gray-500 rounded-lg focus:outline-none focus:shadow-outline"
78-
>
79-
<option value="sort">Blå</option>
80-
</select>
81-
</p>
82-
<p className="pt-1 mt-2 text-xl text-gray-900 ">
83-
<span className="py-2">Størrelse</span>
84-
<select
85-
id="størrelse"
86-
className="block w-64 px-6 py-2 bg-white border border-gray-500 rounded-lg focus:outline-none focus:shadow-outline"
87-
>
88-
<option value="sort">Large</option>
89-
</select>
90-
</p>
91-
*/}
80+
81+
{product.variations && (
82+
<p className="pt-1 mt-4 text-xl text-gray-900">
83+
<span className="py-2">Varianter</span>
84+
<select
85+
id="variant"
86+
name="variant"
87+
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)}}
89+
>
90+
{product.variations.nodes.map(
91+
({ id, name, variationId }) => {
92+
const filteredName = name.split('- ').pop();
93+
94+
return (
95+
<option key={id} value={variationId}>
96+
{filteredName}
97+
</option>
98+
);
99+
}
100+
)}
101+
</select>
102+
</p>
103+
)}
104+
92105
<div className="pt-1 mt-2">
93-
<AddToCartButton product={product} />
106+
{!product.variations && <AddToCartButton product={product} />}
107+
{product.variations && <AddToCartButton product={selectedVariation} />}
94108
</div>
95109
</div>
96110
</div>

utils/const/GQL_QUERIES.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ export const GET_SINGLE_PRODUCT = gql`
2323
... on VariableProduct {
2424
price
2525
id
26+
paColors {
27+
nodes {
28+
name
29+
}
30+
}
31+
paSizes {
32+
nodes {
33+
name
34+
}
35+
}
36+
variations {
37+
nodes {
38+
id
39+
variationId
40+
name
41+
stockStatus
42+
stockQuantity
43+
purchasable
44+
onSale
45+
salePrice
46+
regularPrice
47+
}
48+
}
2649
}
2750
... on ExternalProduct {
2851
price

0 commit comments

Comments
 (0)