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