@wikala/spmkt 2.26.0 → 2.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Product/AddToCart.vue +10 -55
- package/components/Product/BoxAddToCart.vue +149 -0
- package/index.js +2 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="add-to-cart"
|
|
2
|
+
<div class="add-to-cart">
|
|
3
3
|
<template v-if="quantityEnabled && inStock" class="quantity">
|
|
4
4
|
<quantity v-model="qty"></quantity>
|
|
5
5
|
</template>
|
|
@@ -46,10 +46,6 @@ export default {
|
|
|
46
46
|
default: function () {
|
|
47
47
|
return {}
|
|
48
48
|
}
|
|
49
|
-
},
|
|
50
|
-
headless: {
|
|
51
|
-
type: Boolean,
|
|
52
|
-
default: false
|
|
53
49
|
}
|
|
54
50
|
},
|
|
55
51
|
|
|
@@ -199,41 +195,6 @@ export default {
|
|
|
199
195
|
}
|
|
200
196
|
},
|
|
201
197
|
|
|
202
|
-
initHeadless() {
|
|
203
|
-
console.log('initHeadless addToCart')
|
|
204
|
-
this.$bus.$on('externalAddToCart', async (product_id, e) => {
|
|
205
|
-
let btn = e.target
|
|
206
|
-
btn.classList.add('is-loading')
|
|
207
|
-
let resp = await request({
|
|
208
|
-
baseURL: config.BASE_URL,
|
|
209
|
-
url: '/products/' + product_id
|
|
210
|
-
})
|
|
211
|
-
this.$emit('update', resp.data.product_resource)
|
|
212
|
-
this.$nextTick(() => {
|
|
213
|
-
if (!this.product.id) {
|
|
214
|
-
return
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
this.product_id = this.product.id
|
|
218
|
-
if (this.product.variants.length > 0) {
|
|
219
|
-
this.$buefy.dialog.confirm({
|
|
220
|
-
title: 'Proizvod sa varijantama',
|
|
221
|
-
message: 'Otvorićemo stranicu proizvoda da biste odabrali varijantu.',
|
|
222
|
-
confirmText: 'Ok',
|
|
223
|
-
type: 'is-success',
|
|
224
|
-
onConfirm: () => {
|
|
225
|
-
window.location.href = '/'+this.product.slug;
|
|
226
|
-
}
|
|
227
|
-
})
|
|
228
|
-
btn.classList.remove('is-loading')
|
|
229
|
-
return
|
|
230
|
-
}
|
|
231
|
-
this.addToCart()
|
|
232
|
-
btn.classList.remove('is-loading')
|
|
233
|
-
})
|
|
234
|
-
})
|
|
235
|
-
},
|
|
236
|
-
|
|
237
198
|
onSelectVariant(variant_id) {
|
|
238
199
|
//console.log('receiving selectVariant ', variant_id)
|
|
239
200
|
if (!variant_id) {
|
|
@@ -252,8 +213,8 @@ export default {
|
|
|
252
213
|
},
|
|
253
214
|
|
|
254
215
|
handleScroll() {
|
|
255
|
-
if (this.$mq !== 'mobile'
|
|
256
|
-
return
|
|
216
|
+
if (this.$mq !== 'mobile') {
|
|
217
|
+
return
|
|
257
218
|
}
|
|
258
219
|
const element = this.$el
|
|
259
220
|
const pagetop = document.querySelector('#pagetop')
|
|
@@ -264,10 +225,10 @@ export default {
|
|
|
264
225
|
|
|
265
226
|
if (scrollPosition > elementPosition) {
|
|
266
227
|
element.classList.add('add-to-cart-fixed-footer')
|
|
267
|
-
pagetop.classList.add('pos2')
|
|
228
|
+
pagetop.classList.add('pos2')
|
|
268
229
|
} else {
|
|
269
|
-
element.classList.remove('add-to-cart-fixed-footer')
|
|
270
|
-
pagetop.classList.remove('pos2')
|
|
230
|
+
element.classList.remove('add-to-cart-fixed-footer')
|
|
231
|
+
pagetop.classList.remove('pos2')
|
|
271
232
|
}
|
|
272
233
|
}
|
|
273
234
|
|
|
@@ -277,16 +238,10 @@ export default {
|
|
|
277
238
|
|
|
278
239
|
handleBusEvents() {
|
|
279
240
|
this.$bus.$on('selectVariant', this.onSelectVariant)
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
this
|
|
283
|
-
|
|
284
|
-
this.qty = qty
|
|
285
|
-
})
|
|
286
|
-
}
|
|
287
|
-
if (this.headless) {
|
|
288
|
-
this.initHeadless()
|
|
289
|
-
}
|
|
241
|
+
this.$bus.$on('updateQty', (qty) => {
|
|
242
|
+
console.log('received updateQty', qty)
|
|
243
|
+
this.qty = qty
|
|
244
|
+
})
|
|
290
245
|
}
|
|
291
246
|
},
|
|
292
247
|
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="box-add-to-cart" @click="handleClick">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import config from '../../config'
|
|
9
|
+
import _ from 'underscore'
|
|
10
|
+
import GoogleAnalyticsEEC from '../../utils/google-analytics-eec.js'
|
|
11
|
+
|
|
12
|
+
import { request, Cart } from '../../api'
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
name: 'BoxAddToCart',
|
|
16
|
+
|
|
17
|
+
props: {
|
|
18
|
+
productId: {
|
|
19
|
+
type: Number,
|
|
20
|
+
required: true
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
data() {
|
|
25
|
+
return {
|
|
26
|
+
loading: false,
|
|
27
|
+
product: {},
|
|
28
|
+
qty: 1,
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
methods: {
|
|
33
|
+
eecProduct() {
|
|
34
|
+
let eecProduct = {
|
|
35
|
+
item_id: this.product.id,
|
|
36
|
+
item_name: this.product.name,
|
|
37
|
+
price: this.product.price,
|
|
38
|
+
item_brand: this.product.brand ? this.product.brand.name : '',
|
|
39
|
+
item_category: this.product?.category?.path.startsWith('/') ? this.product?.category?.path.substr(1) : this.product?.category?.path,
|
|
40
|
+
quantity: parseInt(this.qty, 10)
|
|
41
|
+
}
|
|
42
|
+
//console.log('eecProduct ', eecProduct)
|
|
43
|
+
return eecProduct
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
productDetails() {
|
|
47
|
+
let product = this.eecProduct()
|
|
48
|
+
product.image_url = this.product.images && this.product.images[0] ? this.product.images[0].url : ''
|
|
49
|
+
return product
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
variantsInStock() {
|
|
53
|
+
let vis = this.product.variants.filter(variant => {
|
|
54
|
+
return variant.in_stock
|
|
55
|
+
})
|
|
56
|
+
return vis.length
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
async updateCart() {
|
|
60
|
+
try {
|
|
61
|
+
let response = await Cart.update({
|
|
62
|
+
mode: this.mode,
|
|
63
|
+
id: this.product.id,
|
|
64
|
+
qty: this.qty
|
|
65
|
+
})
|
|
66
|
+
//console.log(response.data)
|
|
67
|
+
if (response.data) {
|
|
68
|
+
this.$bus.$emit('updateCart', response.data)
|
|
69
|
+
} else {
|
|
70
|
+
throw new Error(this.$t('cart.updateCartErrorUnknown'))
|
|
71
|
+
}
|
|
72
|
+
return response.data
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (!error.message) {
|
|
75
|
+
error.message = this.$t('cart.updateCartError', error.status)
|
|
76
|
+
}
|
|
77
|
+
this.$buefy.dialog.alert({
|
|
78
|
+
title: this.$t('global.error'),
|
|
79
|
+
message: error.message,
|
|
80
|
+
confirmText: 'OK'
|
|
81
|
+
})
|
|
82
|
+
} finally {
|
|
83
|
+
this.loading = false
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
async addToCart(event) {
|
|
88
|
+
this.loading = true
|
|
89
|
+
let cartResponse = await this.updateCart()
|
|
90
|
+
if (cartResponse) {
|
|
91
|
+
this.$emit('success')
|
|
92
|
+
this.$bus.$emit('addToCart', this.productDetails(), this.el$)
|
|
93
|
+
if (!!window.google_tag_manager) {
|
|
94
|
+
GoogleAnalyticsEEC.addToCart(this.eecProduct(), () => {
|
|
95
|
+
this.loadingAddToCart = false
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
async setProduct() {
|
|
102
|
+
this.product = {};
|
|
103
|
+
let resp = await request({
|
|
104
|
+
baseURL: config.BASE_URL,
|
|
105
|
+
url: '/products/' + this.product_id
|
|
106
|
+
})
|
|
107
|
+
this.product = resp.data.product_resource
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
async handleClick(e) {
|
|
111
|
+
let btn = e.target
|
|
112
|
+
btn.classList.add('is-loading')
|
|
113
|
+
|
|
114
|
+
await this.setProduct()
|
|
115
|
+
|
|
116
|
+
if (!this.product.id) {
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if(this.variantsInStock() === 1) {
|
|
121
|
+
this.product_id = this.product.variants.find(variant => variant.in_stock).id
|
|
122
|
+
await this.setProduct();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if(this.variantsInStock() > 1) {
|
|
126
|
+
this.$buefy.dialog.confirm({
|
|
127
|
+
title: 'Proizvod sa varijantama',
|
|
128
|
+
message: 'Otvorićemo stranicu proizvoda da biste odabrali varijantu.',
|
|
129
|
+
confirmText: 'Ok',
|
|
130
|
+
type: 'is-success',
|
|
131
|
+
onConfirm: () => {
|
|
132
|
+
window.location.href = '/'+this.product.slug;
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
btn.classList.remove('is-loading')
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.addToCart()
|
|
140
|
+
btn.classList.remove('is-loading')
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
mounted() {
|
|
146
|
+
this.product_id = this.productId;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
</script>
|
package/index.js
CHANGED
|
@@ -52,6 +52,7 @@ import CategorySort from './components/Category/CategorySort' //t
|
|
|
52
52
|
import LoadMore from './components/Category/LoadMore'
|
|
53
53
|
|
|
54
54
|
import AddToCart from './components/Product/AddToCart' //t
|
|
55
|
+
import BoxAddToCart from './components/Product/BoxAddToCart' //t
|
|
55
56
|
import Quantity from './components/Product/Quantity'
|
|
56
57
|
import Compare from './components/Product/Compare'
|
|
57
58
|
import CompareBox from './components/Product/CompareBox' //t
|
|
@@ -127,6 +128,7 @@ export {
|
|
|
127
128
|
LoadMore,
|
|
128
129
|
|
|
129
130
|
AddToCart,
|
|
131
|
+
BoxAddToCart,
|
|
130
132
|
Quantity,
|
|
131
133
|
Compare,
|
|
132
134
|
CompareBox,
|