Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The current release has been tested and is confirmed working with the following
- Vue Apollo with GraphQL Codegen
- Vue Awesome Swiper for image slider on frontpage
- Responsive design
- Support for simple products
- Support for simple and variable products
- GraphQL-based filters
- CSS animations and transitions
- Form handling and validation with Vue Formulate
Expand All @@ -91,6 +91,5 @@ Check the attributes of the products. Right now the application requires Size an

## TODO

- Look into variable product support
- Make WooCommerce session token expire and get deleted after 24 hours
- Make Algolia look good on mobile
4 changes: 2 additions & 2 deletions components/Cart/AddToCartButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import ADD_TO_CART_MUTATION from '@/apollo/mutations/ADD_TO_CART_MUTATION'

export default {
props: {
product: { type: Object, required: true },
product: { type: [Number, Object], required: true },
},
data() {
return {
Expand All @@ -52,7 +52,7 @@ export default {
mutation: ADD_TO_CART_MUTATION,
variables: { input: productQueryInput },
})
.then(({ data }) => {
.then(() => {
this.loading = false
this.$apollo.queries.cart.refetch()
})
Expand Down
6 changes: 5 additions & 1 deletion components/Products/ShowAllProducts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{{ product.regularPrice }}
</div>
<div class="ml-4 text-xl text-gray-900">
{{ product.salePrice }}
{{ filteredVariantPrice(product.salePrice) }}
</div>
</div>
<div v-else>
Expand All @@ -48,17 +48,21 @@
</template>

<script>
import { filteredVariantPrice } from '@/utils/functions'

export default {
name: 'ShowAllProducts',
props: {
products: { type: Array, required: true },
},

methods: {
productImage(product) {
return product.image
? product.image.sourceUrl
: process.env.placeholderSmallImage
},
filteredVariantPrice,
},
}
</script>
Expand Down
29 changes: 23 additions & 6 deletions components/Products/ShowSingleProduct.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
:alt="product.name"
:src="product.image.sourceUrl"
/>

<img
v-else
id="product-image"
Expand All @@ -24,7 +23,7 @@
<p class="text-3xl font-bold text-left">{{ product.name }}</p>
<div v-if="product.onSale" class="flex">
<p class="pt-1 mt-4 text-3xl text-gray-900">
{{ product.salePrice }}
{{ filteredVariantPrice(product.salePrice) }}
</p>
<p class="pt-1 pl-8 mt-4 text-2xl text-gray-900 line-through">
{{ product.regularPrice }}
Expand All @@ -44,16 +43,24 @@
<span class="py-2">Varianter</span>
<select
id="variant"
v-model="variationProduct"
name="variant"
class="block w-64 px-6 py-2 bg-white border border-gray-500 rounded-lg focus:outline-none focus:shadow-outline"
>
VARIATION
<option
v-for="(variation, index) in product.variations.nodes"
:key="variation.databaseId"
:value="variation.databaseId"
:selected="index === 0"
>
{{ variation.name }}
</option>
</select>
</p>
<div class="pt-1 mt-2">
<CartAddToCartButton
v-if="product.variations"
:product="product"
:product="variationProduct"
/>
<CartAddToCartButton v-else :product="product" />
</div>
Expand All @@ -65,13 +72,23 @@
</template>

<script>
import { stripHTML } from '@/utils/functions'
import { stripHTML, filteredVariantPrice } from '@/utils/functions'

export default {
name: 'ShowSingleProduct',
props: {
product: { type: Object, required: true },
},
methods: { stripHTML },
data() {
return {
// Set default value
variationProduct: 18,
}
},

methods: {
stripHTML,
filteredVariantPrice,
},
}
</script>
7 changes: 6 additions & 1 deletion utils/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ function stripHTML(description) {
return description.replace(/(<([^>]+)>)/gi, '')
}

function filteredVariantPrice(price) {
// Filter price from "kr198.00 - kr299.00" to kr299.00
return price.substring(price.length, price.indexOf('-')).replace('-', '')
}

function createCheckoutData(form) {
const checkoutData = {
clientMutationId: uid(),
Expand Down Expand Up @@ -42,4 +47,4 @@ function createCheckoutData(form) {
return { checkoutData }
}

export { stripHTML, createCheckoutData }
export { stripHTML, createCheckoutData, filteredVariantPrice }