Skip to content

Commit 1dabe34

Browse files
committed
Got variations to work
1 parent edcfe52 commit 1dabe34

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

components/Cart/AddToCartButton.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import ADD_TO_CART_MUTATION from '@/apollo/mutations/ADD_TO_CART_MUTATION'
3131
3232
export default {
3333
props: {
34-
product: { type: Object, required: true },
34+
product: { type: [Number, Object], required: true },
3535
},
3636
data() {
3737
return {
@@ -52,7 +52,7 @@ export default {
5252
mutation: ADD_TO_CART_MUTATION,
5353
variables: { input: productQueryInput },
5454
})
55-
.then(({ data }) => {
55+
.then(() => {
5656
this.loading = false
5757
this.$apollo.queries.cart.refetch()
5858
})

components/Products/ShowSingleProduct.vue

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
:alt="product.name"
1313
:src="product.image.sourceUrl"
1414
/>
15-
1615
<img
1716
v-else
1817
id="product-image"
@@ -44,16 +43,24 @@
4443
<span class="py-2">Varianter</span>
4544
<select
4645
id="variant"
46+
v-model="variationProduct"
4747
name="variant"
4848
class="block w-64 px-6 py-2 bg-white border border-gray-500 rounded-lg focus:outline-none focus:shadow-outline"
4949
>
50-
VARIATION
50+
<option
51+
v-for="(variation, index) in product.variations.nodes"
52+
:key="variation.databaseId"
53+
:value="variation.databaseId"
54+
:selected="index === 0"
55+
>
56+
{{ variation.name }}
57+
</option>
5158
</select>
5259
</p>
5360
<div class="pt-1 mt-2">
5461
<CartAddToCartButton
5562
v-if="product.variations"
56-
:product="product"
63+
:product="variationProduct"
5764
/>
5865
<CartAddToCartButton v-else :product="product" />
5966
</div>
@@ -72,6 +79,16 @@ export default {
7279
props: {
7380
product: { type: Object, required: true },
7481
},
75-
methods: { stripHTML, filteredVariantPrice },
82+
data() {
83+
return {
84+
// Set default value
85+
variationProduct: 18,
86+
}
87+
},
88+
89+
methods: {
90+
stripHTML,
91+
filteredVariantPrice,
92+
},
7693
}
7794
</script>

0 commit comments

Comments
 (0)