mirror of
https://github.com/KevinMidboe/planetposen.git
synced 2025-10-29 09:40:31 +00:00
Product reads variations and uses new sizePicker.
Product component no longer has static data, but reads from variations and changes stock and amount based on selected size.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<main role="main" v-if="product">
|
<main role="main" v-if="product">
|
||||||
<div class="banner padding-bottom--lg" :class="'bg-' + color">
|
<div class="banner padding-bottom--lg" :class="'bg-' + product.color">
|
||||||
<div class="banner-content top-show-sm col-wrap max-width">
|
<div class="banner-content top-show-sm col-wrap max-width">
|
||||||
<h1>{{ product.name }}</h1>
|
<h1>{{ product.name }}</h1>
|
||||||
</div>
|
</div>
|
||||||
@@ -16,14 +16,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-6 details">
|
<div class="col-6 details">
|
||||||
<div class="pricing">
|
<div class="pricing">
|
||||||
<span :class="{ sale: selectedVariation.discount }">24.99 kr</span>
|
<span :class="{ sale: selectedVariation.discount }">
|
||||||
<span v-if="selectedVariation.discount">19.99 kr</span>
|
{{ selectedVariation.price }} kr
|
||||||
|
</span>
|
||||||
|
<span v-if="selectedVariation.discount">
|
||||||
|
{{ selectedVariation.discount }} kr</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p v-if="product.description">{{ product.description }}</p>
|
<p v-if="product.description">{{ product.description }}</p>
|
||||||
<p v-else class="description">Notatbøkene fra All Pine Press er trykket i Oslo og papir fra Hellefoss Paper AS i Hokksund. (Notatbøkene er uten linjer)</p>
|
<p v-else class="description">Notatbøkene fra All Pine Press er trykket i Oslo og papir fra Hellefoss Paper AS i Hokksund. (Notatbøkene er uten linjer)</p>
|
||||||
|
|
||||||
<div class="stock" v-if="inStock">
|
<div class="stock" v-if="selectedVariation.stock > 0">
|
||||||
<i class="icon icon--checkmark-circle"></i>
|
<i class="icon icon--checkmark-circle"></i>
|
||||||
På lager
|
På lager
|
||||||
</div>
|
</div>
|
||||||
@@ -34,10 +37,19 @@
|
|||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<!-- Variation picker -->
|
<!-- Variation picker -->
|
||||||
|
Size:
|
||||||
|
<size-picker class="variationPicker" :sizes="availableSizes"
|
||||||
|
@selectedSize="sizeSelected" :sizeVariable="selectedVariation.size" />
|
||||||
|
|
||||||
<!-- Amount picker -->
|
<!-- Amount picker -->
|
||||||
|
|
||||||
|
<div v-if="selectedVariation.stock > 0">
|
||||||
|
Quantity:
|
||||||
|
<input type="number" value="1" min="1" :max="selectedVariation.stock" />
|
||||||
|
</div>
|
||||||
<!-- Buy button -->
|
<!-- Buy button -->
|
||||||
<Button color="black" :small="true" @click="addToCart" :scaleRotate="true">Add to cart</Button>
|
|
||||||
|
<Button color="black" :small="true" @click="addToCart" :scaleRotate="true" :disabled="selectedVariation.stock == 0">Add to cart</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
@@ -53,10 +65,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Button from '@/components/ui/Button';
|
import Button from '@/components/ui/Button';
|
||||||
|
import SizePicker from '@/components/ui/sizePicker';
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { Button },
|
components: { Button, SizePicker },
|
||||||
props: {
|
props: {
|
||||||
product: {
|
product: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@@ -66,11 +79,17 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
placeholderWidth: '0px',
|
placeholderWidth: '0px',
|
||||||
color: Math.random() > 0.5 ? 'yellow' : 'blue',
|
availableSizes: undefined,
|
||||||
inStock: Math.random() > 0.5,
|
|
||||||
selectedVariation: { discount: Math.random() > 0.5 ? true : false }
|
selectedVariation: { discount: Math.random() > 0.5 ? true : false }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
beforeMount() {
|
||||||
|
this.selectedVariation = this.product.variations[0];
|
||||||
|
|
||||||
|
if (this.product.variations.length)
|
||||||
|
this.availableSizes = this.product.variations.map(el => el.size)
|
||||||
|
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
setTimeout(this.squareImagePlaceholder, 10);
|
setTimeout(this.squareImagePlaceholder, 10);
|
||||||
},
|
},
|
||||||
@@ -83,10 +102,20 @@ export default {
|
|||||||
this.color = this.product.color;
|
this.color = this.product.color;
|
||||||
if (newVal.image == '')
|
if (newVal.image == '')
|
||||||
setTimeout(this.squareImagePlaceholder, 10);
|
setTimeout(this.squareImagePlaceholder, 10);
|
||||||
|
if (this.product.variations.length) {
|
||||||
|
this.availableSizes = this.product.variations.map(el => el.size)
|
||||||
|
|
||||||
|
if (this.selectedVariation == undefined)
|
||||||
|
this.selectedVariation = this.product.variations[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
sizeSelected(size) {
|
||||||
|
const variationIndex = this.product.variations.findIndex(variation => variation.size == size)
|
||||||
|
this.selectedVariation = this.product.variations[variationIndex];
|
||||||
|
},
|
||||||
addToCart() {
|
addToCart() {
|
||||||
store.dispatch('cartModule/addItemToCart', { ...this.product });
|
store.dispatch('cartModule/addItemToCart', { ...this.product });
|
||||||
},
|
},
|
||||||
@@ -165,7 +194,7 @@ h1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.pricing {
|
.pricing {
|
||||||
font-size: 2rem;
|
font-size: 3rem;
|
||||||
|
|
||||||
& .sale {
|
& .sale {
|
||||||
text-decoration: line-through;
|
text-decoration: line-through;
|
||||||
@@ -174,4 +203,24 @@ h1 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.variationPicker {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
border-width: 4px;
|
||||||
|
border-color: black;
|
||||||
|
padding: 0.5rem;
|
||||||
|
font-size: 2rem;
|
||||||
|
display: block;
|
||||||
|
|
||||||
|
&[type=number] {
|
||||||
|
width: 5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user