Skip to content

Commit edcfe52

Browse files
committed
Correctly show price on variable product on sale
1 parent 6182b5b commit edcfe52

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

components/Products/ShowAllProducts.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{{ product.regularPrice }}
3333
</div>
3434
<div class="ml-4 text-xl text-gray-900">
35-
{{ product.salePrice }}
35+
{{ filteredVariantPrice(product.salePrice) }}
3636
</div>
3737
</div>
3838
<div v-else>
@@ -48,17 +48,21 @@
4848
</template>
4949

5050
<script>
51+
import { filteredVariantPrice } from '@/utils/functions'
52+
5153
export default {
5254
name: 'ShowAllProducts',
5355
props: {
5456
products: { type: Array, required: true },
5557
},
58+
5659
methods: {
5760
productImage(product) {
5861
return product.image
5962
? product.image.sourceUrl
6063
: process.env.placeholderSmallImage
6164
},
65+
filteredVariantPrice,
6266
},
6367
}
6468
</script>

components/Products/ShowSingleProduct.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<p class="text-3xl font-bold text-left">{{ product.name }}</p>
2525
<div v-if="product.onSale" class="flex">
2626
<p class="pt-1 mt-4 text-3xl text-gray-900">
27-
{{ product.salePrice }}
27+
{{ filteredVariantPrice(product.salePrice) }}
2828
</p>
2929
<p class="pt-1 pl-8 mt-4 text-2xl text-gray-900 line-through">
3030
{{ product.regularPrice }}
@@ -65,13 +65,13 @@
6565
</template>
6666

6767
<script>
68-
import { stripHTML } from '@/utils/functions'
68+
import { stripHTML, filteredVariantPrice } from '@/utils/functions'
6969
7070
export default {
7171
name: 'ShowSingleProduct',
7272
props: {
7373
product: { type: Object, required: true },
7474
},
75-
methods: { stripHTML },
75+
methods: { stripHTML, filteredVariantPrice },
7676
}
7777
</script>

utils/functions.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ function stripHTML(description) {
44
return description.replace(/(<([^>]+)>)/gi, '')
55
}
66

7+
function filteredVariantPrice(price) {
8+
// Filter price from "kr198.00 - kr299.00" to kr299.00
9+
return price.substring(price.length, price.indexOf('-')).replace('-', '')
10+
}
11+
712
function createCheckoutData(form) {
813
const checkoutData = {
914
clientMutationId: uid(),
@@ -42,4 +47,4 @@ function createCheckoutData(form) {
4247
return { checkoutData }
4348
}
4449

45-
export { stripHTML, createCheckoutData }
50+
export { stripHTML, createCheckoutData, filteredVariantPrice }

0 commit comments

Comments
 (0)