Vue.component('product', { template: `
-{{discount_percentage}}%
{{product.name_en}}
{{ product.original_price }} {{ product.currency }} {{ product.price }} {{ product.currency }}
`, props: ['product', 'site_url', 'full_width'], data: function () { return { 'discount_percentage': Math.round(100 - ((this.product.price / this.product.original_price) * 100)), 'href_url': this.site_url + '/product/' + this.product.id + '/' + this.product.name_en.replace(/\//g, '').replace('&', '').replace('%', ''), 'show_discount': false } }, watch: { product: { handler: function (newVal, oldVal) { this.href_url = this.site_url + '/product/' + this.product.id + '/' + this.product.name_en.replace('/', '').replace(/\//g, '').replace('&', '').replace('%', ''); var calculatedStuff = Math.round(100 - ((this.product.price / this.product.original_price) * 100)); this.discount_percentage = calculatedStuff; if(Number(this.product.price) < Number(this.product.original_price)) { this.show_discount = true; } else { this.show_discount = false; } } } }, methods: { addToCartThis: function (product) { addToCart(product); }, quickViewThis: function (product) { quickView(product); } }, created: function() { if(Number(this.product.price) < Number(this.product.original_price)) { this.show_discount = true; } else { this.show_discount = false; } } });