@wikala/spmkt 2.17.0 → 2.18.1

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.
@@ -170,8 +170,10 @@ export default {
170
170
  },
171
171
 
172
172
  optionSelect(optionValue, option) {
173
+ //console.log('opt select')
173
174
  this.selectedVariant = null
174
175
  this.fittingUnselected = []
176
+ this.updateDiscountBadge()
175
177
  if (this.selectedOptions[option.id] === optionValue) {
176
178
  this.$delete(this.selectedOptions, option.id)
177
179
  } else {
@@ -181,6 +183,8 @@ export default {
181
183
  this.selectedVariant = this.getMatchingVariant()
182
184
  if (!this.selectedVariant) {
183
185
  this.setFittingUnselected()
186
+ } else {
187
+ this.updateDiscountBadge()
184
188
  }
185
189
  this.emitEvents()
186
190
  },
@@ -201,11 +205,28 @@ export default {
201
205
  this.selectedVariant.options.forEach((vo) => {
202
206
  this.$set(this.selectedOptions, vo.attribute_id, vo.value)
203
207
  })
208
+
209
+ this.updateDiscountBadge(variant)
210
+
204
211
  this.$nextTick(() => {
205
212
  this.emitEvents()
206
213
  })
207
214
  },
208
215
 
216
+ updateDiscountBadge() {
217
+ let discountPercent = Math.round((this.selectedVariant.compare_price - this.selectedVariant.price)/this.selectedVariant.compare_price * 100, 0)
218
+ let badge = document.querySelector('.product-main .badge-discount')
219
+ if(!badge) {
220
+ return
221
+ }
222
+ //console.log('setting bagde-discount', -discountPercent+'%')
223
+ badge.style.visibility = 'hidden';
224
+ if(discountPercent > 0) {
225
+ badge.style.visibility = 'visible';
226
+ badge.textContent = `-${discountPercent}%`
227
+ }
228
+ },
229
+
209
230
  getVariantByOption(optionId, optionValue) {
210
231
  if (this.productVariantOptions.length !== 1) {
211
232
  return {}
@@ -250,6 +271,7 @@ export default {
250
271
  return
251
272
  }
252
273
  let urlVariant = this.getVariantFromURL()
274
+
253
275
  if(urlVariant) {
254
276
  this.setSelectedVariant(urlVariant)
255
277
  } else {
@@ -257,18 +279,22 @@ export default {
257
279
  _.filter(this.productVariants, (item) => item.in_stock && item.price > 0),
258
280
  'price'
259
281
  )
282
+
260
283
  if (inStockVariants.length === 0) {
261
284
  return
262
285
  }
263
- //console.log('preselecting variant', inStockVariants[0])
264
- if (this.render === 'pricetags') {
286
+ if (this.render === 'pricetags' || inStockVariants.length === 1) {
265
287
  this.setSelectedVariant(inStockVariants[0])
266
288
  } else {
267
- if(inStockVariants.length === 1) {
268
- this.setSelectedVariant(inStockVariants[0])
269
- }
289
+ let discounted = inStockVariants.find(isv => isv.price !== isv.compare_price);
290
+ if(discounted) {
291
+ this.setSelectedVariant(discounted)
292
+ } else {
293
+ this.setSelectedVariant(inStockVariants[0])
294
+ }
270
295
  }
271
296
  }
297
+
272
298
  },
273
299
 
274
300
  emitEvents() {
@@ -300,7 +326,7 @@ export default {
300
326
  this.$nextTick(() => {
301
327
  this.preselect()
302
328
  this.setOptionCombinations()
303
- this.setSelectedVariant(this.getVariantFromURL())
329
+ //this.setSelectedVariant(this.getVariantFromURL())
304
330
  })
305
331
  }
306
332
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wikala/spmkt",
3
- "version": "2.17.0",
3
+ "version": "2.18.1",
4
4
  "private": false,
5
5
  "description": "supermarket",
6
6
  "scripts": {