@ecomplus/storefront-components 1.0.0-beta.180 → 1.0.0-beta.182

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomplus/storefront-components",
3
- "version": "1.0.0-beta.180",
3
+ "version": "1.0.0-beta.182",
4
4
  "description": "Vue components for E-Com Plus Storefront",
5
5
  "main": "dist/storefront-components.min.js",
6
6
  "scripts": {
@@ -87,7 +87,7 @@
87
87
  </template>
88
88
 
89
89
  <a-alert
90
- :key="`alert-${alertVariant}`"
90
+ :key="`alert-${alertVariant}-${localCouponCode}`"
91
91
  :can-show="!isLoading && Boolean(alertText)"
92
92
  :variant="alertVariant"
93
93
  @dismiss="alertText = null"
@@ -55,7 +55,8 @@
55
55
  leave-active-class="animated fadeOutDown"
56
56
  >
57
57
  <div
58
- v-if="canSelectServices && !canAutoSelectService && selectedService === null"
58
+ v-if="canSelectServices && !canAutoSelectService &&
59
+ selectedService === null && shippingServices.length"
59
60
  class="shipping-calculator__label"
60
61
  >
61
62
  <i class="i-arrow-down animated wobble"></i>
@@ -95,7 +95,7 @@ export default {
95
95
  this.selectedShippingPrice = service.shipping_line
96
96
  ? service.shipping_line.total_price
97
97
  : 0
98
- },
98
+ }
99
99
  },
100
100
 
101
101
  created () {
@@ -80,6 +80,7 @@ export default {
80
80
  default: true
81
81
  },
82
82
  modulesPayload: Object,
83
+ paymentGateway: Object,
83
84
  ecomCart: {
84
85
  type: Object,
85
86
  default () {
@@ -125,6 +126,22 @@ export default {
125
126
  canAddCoupon () {
126
127
  return !this.couponCode || !this.isCouponApplied ||
127
128
  this.couponCode !== this.localCouponCode
129
+ },
130
+
131
+ paymentGatewayDiscount () {
132
+ if (!this.paymentGateway) return 0
133
+ const { discount } = this.paymentGateway
134
+ if (!discount || !discount.value) return 0
135
+ const applyAt = discount.apply_at || 'total'
136
+ const maxDiscount = applyAt === 'total' ? this.localAmountTotal : this.amount[applyAt]
137
+ if (maxDiscount > 0) {
138
+ const { type, value } = discount
139
+ if (type === 'percentage') {
140
+ return maxDiscount * value / 100
141
+ }
142
+ return value <= maxDiscount ? value : maxDiscount
143
+ }
144
+ return 0
128
145
  }
129
146
  },
130
147
 
@@ -133,7 +150,8 @@ export default {
133
150
  const amount = this.amount || {
134
151
  subtotal: this.ecomCart.data.subtotal
135
152
  }
136
- this.localAmountTotal = (amount.subtotal || 0) + (amount.freight || 0)
153
+ this.localAmountTotal = (amount.subtotal || 0) +
154
+ (amount.freight || 0) - this.paymentGatewayDiscount
137
155
  },
138
156
 
139
157
  parseDiscountOptions (listResult = []) {
@@ -230,7 +248,7 @@ export default {
230
248
  subtotal: this.localAmountTotal,
231
249
  ...this.amount,
232
250
  total: this.localAmountTotal,
233
- discount: 0
251
+ discount: this.paymentGatewayDiscount
234
252
  },
235
253
  items: this.ecomCart.data.items,
236
254
  ...data
@@ -268,12 +286,23 @@ export default {
268
286
  ) {
269
287
  this.fetchDiscountOptions()
270
288
  }
289
+ },
290
+
291
+ scheduleUpdateDiscount () {
292
+ if (this.isUpdateSheduled) return
293
+ this.isUpdateSheduled = true
294
+ this.$nextTick(() => {
295
+ setTimeout(() => {
296
+ this.updateDiscount()
297
+ this.isUpdateSheduled = false
298
+ }, 600)
299
+ })
271
300
  }
272
301
  },
273
302
 
274
303
  watch: {
275
304
  couponCode (couponCode) {
276
- if (couponCode !== this.couponCode) {
305
+ if (couponCode !== this.localCouponCode) {
277
306
  this.localCouponCode = couponCode
278
307
  if (couponCode && !this.isFormVisible) {
279
308
  this.isFormVisible = true
@@ -281,6 +310,12 @@ export default {
281
310
  }
282
311
  },
283
312
 
313
+ localCouponCode () {
314
+ if (this.alertVariant === 'info') {
315
+ this.alertText = null
316
+ }
317
+ },
318
+
284
319
  isFormAlwaysVisible (isFormVisible) {
285
320
  if (isFormVisible) {
286
321
  this.isFormVisible = true
@@ -296,14 +331,8 @@ export default {
296
331
  },
297
332
 
298
333
  localAmountTotal (total, oldTotal) {
299
- if (oldTotal !== null && Math.abs(total - oldTotal) > 0.01 && !this.isUpdateSheduled) {
300
- this.isUpdateSheduled = true
301
- this.$nextTick(() => {
302
- setTimeout(() => {
303
- this.updateDiscount()
304
- this.isUpdateSheduled = false
305
- }, 600)
306
- })
334
+ if (oldTotal !== null && Math.abs(total - oldTotal) > 0.01) {
335
+ this.scheduleUpdateDiscount()
307
336
  }
308
337
  },
309
338
 
@@ -312,6 +341,10 @@ export default {
312
341
  this.fixAmount()
313
342
  },
314
343
  deep: true
344
+ },
345
+
346
+ paymentGatewayDiscount () {
347
+ this.scheduleUpdateDiscount()
315
348
  }
316
349
  },
317
350
 
@@ -208,6 +208,8 @@ export default {
208
208
  })
209
209
  if (this.canAutoSelectService) {
210
210
  this.setSelectedService(0)
211
+ } else {
212
+ this.selectedService = null
211
213
  }
212
214
  this.hasPaidOption = Boolean(this.shippingServices.find(service => {
213
215
  return service.shipping_line.total_price || service.shipping_line.price