@wikala/spmkt 2.31.1 → 3.0.0-beta.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.
Files changed (132) hide show
  1. package/MIGRATION_GUIDE.md +310 -0
  2. package/api/product.js +1 -0
  3. package/api/request.js +12 -6
  4. package/api/user.js +1 -1
  5. package/components/Account/AccountDashboard.vue +101 -101
  6. package/components/Account/AccountStore.js +57 -31
  7. package/components/Account/AffiliateReport.vue +56 -60
  8. package/components/Account/{OrderDetail.vue → Orders/OrderDetail.vue} +44 -30
  9. package/components/Account/Orders/Orders.vue +124 -0
  10. package/components/Account/{AccountSettings.vue → Settings/AccountSettings.vue} +4 -4
  11. package/components/Account/Settings/ChangeEmail.vue +136 -0
  12. package/components/Account/Settings/ChangeName.vue +82 -0
  13. package/components/Account/Settings/ChangePassword.vue +91 -0
  14. package/components/Address/Address.vue +38 -57
  15. package/components/Address/AddressBook.vue +77 -57
  16. package/components/Address/AddressSelect.vue +94 -87
  17. package/components/Address/Edit.vue +253 -265
  18. package/components/Address/PostalCode.vue +22 -21
  19. package/components/AgeGate.vue +11 -5
  20. package/components/Auth/Login.vue +62 -44
  21. package/components/Auth/Register.vue +82 -60
  22. package/components/Auth/ResetPassword.vue +45 -30
  23. package/components/Cart/AgeVerification/AgeChecker.vue +3 -3
  24. package/components/Cart/CartBadge.vue +15 -4
  25. package/components/Cart/CartBox.vue +19 -11
  26. package/components/Cart/CartItem.vue +3 -3
  27. package/components/Cart/CartMode.vue +6 -5
  28. package/components/Cart/CartPreview.vue +24 -18
  29. package/components/Cart/CreditCard/Everyware.vue +10 -10
  30. package/components/Cart/CreditCard/ExtendedCreditCard.vue +5 -5
  31. package/components/Cart/CreditCard/SquarePay.vue +18 -16
  32. package/components/Cart/CreditCard/StandardCreditCard.vue +9 -9
  33. package/components/Cart/Delivery/Delivery.vue +16 -12
  34. package/components/Cart/Delivery/DeliveryAddress.vue +1 -1
  35. package/components/Cart/Delivery/DeliveryMethods.vue +1 -1
  36. package/components/Cart/Delivery/DeliveryOptions.vue +15 -9
  37. package/components/Cart/Delivery/DeliveryTypes.vue +8 -5
  38. package/components/Cart/Delivery/ReservationSlots.vue +14 -8
  39. package/components/Cart/Disclaimer.vue +1 -1
  40. package/components/Cart/OrderConfirmation.vue +1 -1
  41. package/components/Cart/Payment/Payment.vue +37 -33
  42. package/components/Cart/Payment/PaymentMethods.vue +6 -4
  43. package/components/Cart/ReviewAndSubmit.vue +9 -7
  44. package/components/Cart/ShoppingCart.vue +42 -31
  45. package/components/Cart/Store/actions.js +1 -1
  46. package/components/Cart/Store/getters.js +2 -1
  47. package/components/Cart/Store/index.js +1 -1
  48. package/components/Cart/Store/mutations.js +9 -7
  49. package/components/Cart/Store/state.js +2 -2
  50. package/components/Cart/UserIdentity.vue +1 -1
  51. package/components/Category/CategoryFilter.vue +128 -114
  52. package/components/Category/CategorySort.vue +44 -32
  53. package/components/Category/LoadMore.vue +39 -23
  54. package/components/DeliverTo.vue +10 -15
  55. package/components/DeliveryNotice.vue +72 -68
  56. package/components/DobInput.vue +24 -24
  57. package/components/Gmaps/GmapsAutocomplete.vue +139 -78
  58. package/components/Gmaps/GmapsLocations.vue +1 -1
  59. package/components/Gmaps/GmapsSingleLocation.vue +121 -87
  60. package/components/MobileMenu/icons/LeftArrowIcon.vue +1 -1
  61. package/components/MobileMenu/icons/MenuIcon.vue +1 -1
  62. package/components/MobileMenu/icons/RightArrowIcon.vue +1 -1
  63. package/components/ModalContainer/ModalContainer.vue +20 -13
  64. package/components/ModalContainer/index.js +62 -18
  65. package/components/Product/AddToCart.vue +237 -221
  66. package/components/Product/BoxAddToCart.vue +114 -86
  67. package/components/Product/Compare.vue +91 -49
  68. package/components/Product/CompareBox.vue +128 -123
  69. package/components/Product/Lookup.vue +92 -65
  70. package/components/Product/Photo.vue +105 -66
  71. package/components/Product/Price.vue +64 -43
  72. package/components/Product/ProductAutocomplete.vue +52 -57
  73. package/components/Product/ProductBox.vue +61 -38
  74. package/components/Product/ProductImages.vue +83 -86
  75. package/components/Product/Quantity.vue +115 -53
  76. package/components/Product/QuickView.vue +52 -45
  77. package/components/Product/RelatedProducts.vue +88 -23
  78. package/components/Product/SKU.vue +27 -8
  79. package/components/Product/Variants.vue +336 -342
  80. package/components/Product/reviews-questions/ProductQuestions.vue +226 -198
  81. package/components/Product/reviews-questions/ProductReviews.vue +122 -107
  82. package/components/Product/reviews-questions/Review.vue +54 -59
  83. package/components/Product/reviews-questions/ReviewForm.vue +222 -170
  84. package/components/Product/reviews-questions/ReviewImages.vue +197 -216
  85. package/components/Product/reviews-questions/Vote.vue +83 -57
  86. package/components/QuantityInput.vue +18 -8
  87. package/components/RangeInput.vue +15 -8
  88. package/components/Recaptcha.vue +8 -1
  89. package/components/SelectShippingCountry.vue +81 -62
  90. package/components/TimedOffer.vue +59 -74
  91. package/composables/globals.js +53 -0
  92. package/config.js +5 -2
  93. package/index.js +41 -10
  94. package/install.js +88 -0
  95. package/locales/en.json +2 -1
  96. package/locales/sr.json +2 -1
  97. package/package.json +49 -37
  98. package/utils/animate.css +50 -0
  99. package/utils/animate.js +1 -1
  100. package/utils/buefy.js +62 -0
  101. package/utils/directives.js +28 -45
  102. package/utils/event-bus.js +56 -0
  103. package/utils/filters.js +24 -7
  104. package/utils/format-date.js +17 -0
  105. package/utils/{gmaps.js → google/gmaps.js} +43 -10
  106. package/utils/{google-analytics-eec.js → google/google-analytics-eec.js} +7 -7
  107. package/utils/random-id.js +10 -0
  108. package/babel.config.js +0 -5
  109. package/components/Account/ChangeEmail.vue +0 -133
  110. package/components/Account/ChangeName.vue +0 -92
  111. package/components/Account/ChangePassword.vue +0 -94
  112. package/components/Account/CreditCards.vue +0 -18
  113. package/components/Account/Orders.vue +0 -110
  114. package/components/Account/Settings.vue +0 -18
  115. package/components/Cart/Delivery/DeliveryAddressGuest.spec.js +0 -128
  116. package/components/Cart/Delivery/DeliveryTypes.spec.js +0 -83
  117. package/components/Cart/PCIBadge/SecurityMetrics.vue +0 -11
  118. package/components/Instagram.vue +0 -49
  119. package/components/ProductImageModal.vue +0 -41
  120. package/jest.config.js +0 -16
  121. package/test/e2e/.babelrc.js +0 -8
  122. package/test/e2e/.eslintrc.js +0 -11
  123. package/test/e2e/accAuth.spec.js +0 -64
  124. package/test/e2e/ageGate.spec.js +0 -26
  125. package/test/e2e/checkout.spec.js +0 -106
  126. package/test/e2e/compare.spec.js +0 -52
  127. package/test/e2e/config/data.js +0 -21
  128. package/test/e2e/config/routes.js +0 -11
  129. package/test/e2e/region.spec.js +0 -46
  130. package/test/e2e/search.spec.js +0 -32
  131. package/tests/vueBuefy.js +0 -4
  132. package/tsconfig.json +0 -8
@@ -4,7 +4,7 @@
4
4
  <strong :class="{ 'has-text-danger': highlight }">{{ $t('product.chooseProductOptions') }}</strong>
5
5
  </div>
6
6
  <div class="variant-options">
7
- <div v-for="vOption in productVariantOptions" class="variant-option">
7
+ <div v-for="vOption in productVariantOptions" :key="vOption.id" class="variant-option">
8
8
  <div v-if="render !== 'pricetags'" class="voption-name">
9
9
  {{ vOption.name }}
10
10
  <span></span>
@@ -12,18 +12,19 @@
12
12
  <div class="voption-values">
13
13
  <div
14
14
  v-for="(optionValue, index) in vOption.values"
15
- v-if="render !== 'pricetags' || (vOption.prices && vOption.prices[optionValue] > 0)"
15
+ v-show="render !== 'pricetags' || (vOption.prices && vOption.prices[optionValue] > 0)"
16
+ :key="index"
16
17
  :class="['voption-value', 'is-flex', 'is-flex-direction-column', 'button', 'is-small', { 'pricetag': render === 'pricetags'}, { 'is-active': selectedOptions[vOption.id] === optionValue }]"
17
- :disabled="isOptionDisabled(vOption.id + '-' + optionValue)"
18
+ :disabled="isOptionDisabled(vOption.id + '-' + optionValue) || undefined"
18
19
  @click="optionSelect(optionValue, vOption)"
19
20
  >
20
21
  <div>{{ optionValue }}<template v-if="render === 'pricetags'">{{ vOption.measurement_unit }}</template></div>
21
- <Pass :vbo="getVariantByOption(vOption.id, optionValue)">
22
- <div v-if="render === 'pricetags'" slot-scope="{ vbo }">
23
- <span class="price-old" v-if="vbo.compare_price > 0 && vbo.price !== vbo.compare_price">{{ formatMoney(vbo.compare_price) }}</span>
24
- <span class="price">{{ formatMoney(vbo.price) }}</span>
25
- </div>
26
- </Pass>
22
+ <div v-if="render === 'pricetags'">
23
+ <template v-if="getVariantByOption(vOption.id, optionValue).price">
24
+ <span class="price-old" v-if="getVariantByOption(vOption.id, optionValue).compare_price > 0 && getVariantByOption(vOption.id, optionValue).price !== getVariantByOption(vOption.id, optionValue).compare_price">{{ $filters.formatMoney(getVariantByOption(vOption.id, optionValue).compare_price) }}</span>
25
+ <span class="price">{{ $filters.formatMoney(getVariantByOption(vOption.id, optionValue).price) }}</span>
26
+ </template>
27
+ </div>
27
28
  </div>
28
29
  </div>
29
30
  </div>
@@ -31,375 +32,368 @@
31
32
  </div>
32
33
  </template>
33
34
 
34
- <script>
35
- import _ from 'underscore'
35
+ <script setup>
36
+ import { ref, reactive, computed, watch, onMounted, onBeforeUnmount, nextTick } from 'vue'
36
37
  import { formatMoney } from '../../utils/filters'
37
- import formatDate from 'intl-dateformat'
38
+ import { useBus } from '../../composables/globals'
39
+ import _ from 'underscore'
40
+ import formatDate from '../../utils/format-date'
38
41
 
39
- const Pass = {
40
- name: 'Pass',
41
- render() {
42
- return this.$scopedSlots.default(this.$attrs)
42
+ const props = defineProps({
43
+ product: {
44
+ type: Object,
45
+ default: () => ({})
46
+ },
47
+ render: {
48
+ type: String,
49
+ default: 'tags'
50
+ },
51
+ variantId: {
52
+ type: Number
53
+ },
54
+ badgeSelector: {
55
+ type: String,
56
+ default: '.product-in-stock .discount.badge'
57
+ },
58
+ overridePriceNotificationSelector: {
59
+ type: String,
60
+ default: '.override-price-active'
61
+ },
62
+ discountInfoSelector: {
63
+ type: String,
64
+ default: '.discount-notice'
65
+ }
66
+ })
67
+
68
+ const emit = defineEmits(['update'])
69
+
70
+ const $bus = useBus()
71
+
72
+ // Reactive state
73
+ const selectedVariant = ref(null)
74
+ const selectedOptions = reactive({})
75
+ const productVariantOptions = ref([])
76
+ const productVariants = ref([])
77
+ const optionCombinations = ref([])
78
+ const fittingUnselected = ref([])
79
+ const highlight = ref(false)
80
+
81
+ // Computed
82
+ const selectedEntries = computed(() => {
83
+ return Object.entries(selectedOptions)
84
+ .map((so) => so[0] + '-' + so[1])
85
+ .sort()
86
+ })
87
+
88
+ // Watch
89
+ watch(() => props.product, (val) => {
90
+ if (val && val.variant_options) {
91
+ productVariantOptions.value = val.variant_options
92
+ productVariants.value = val.variants
93
+ setOptionCombinations()
43
94
  }
95
+ }, { deep: true })
96
+
97
+ // Methods
98
+ function setOptionCombinations() {
99
+ optionCombinations.value = []
100
+ let allOptions = _.pluck(productVariants.value, 'options')
101
+ allOptions.forEach((options) => {
102
+ let v = []
103
+ options.forEach((o) => {
104
+ v.push(o.attribute_id + '-' + o.value)
105
+ })
106
+ optionCombinations.value.push(v)
107
+ })
44
108
  }
45
109
 
46
- export default {
47
- name: 'Variants',
48
-
49
- components: { Pass },
50
-
51
- props: {
52
- product: {
53
- type: Object,
54
- default: function () {
55
- return {}
56
- }
57
- },
58
- render: {
59
- type: String,
60
- default: 'tags'
61
- },
62
- variantId: {
63
- type: Number
64
- },
65
- badgeSelector: {
66
- type: String,
67
- default: '.product-in-stock .discount.badge'
68
- },
69
- overridePriceNotificationSelector: {
70
- type: String,
71
- default: '.override-price-active'
72
- },
73
- discountInfoSelector: {
74
- type: String,
75
- default: '.discount-notice'
76
- }
77
- },
110
+ function setFittingUnselected() {
111
+ let fitting = []
112
+ fittingUnselected.value = []
113
+ if (selectedEntries.value.length === 1) {
114
+ let selectedKey = parseInt(Object.keys(selectedOptions)[0])
115
+ let selectedKeyOptionValues = _.findWhere(productVariantOptions.value, { id: selectedKey }).values
116
+ fitting = selectedKeyOptionValues.map((skov) => selectedKey + '-' + skov)
117
+ }
118
+ selectedEntries.value.forEach((so) => {
119
+ fitting.push(_.filter(optionCombinations.value, (c) => c.includes(so)))
120
+ })
121
+ fittingUnselected.value = _.uniq(_.flatten(fitting))
122
+ }
78
123
 
79
- data() {
80
- return {
81
- selectedVariant: 0,
82
- selectedOptions: {},
83
- productVariantOptions: [],
84
- productVariants: [],
85
- optionCombinations: [],
86
- fittingUnselected: [],
87
- highlight: false,
88
- variantByOption: {}
124
+ function getMatchingVariant() {
125
+ if (selectedEntries.value.length !== productVariantOptions.value.length) {
126
+ return false
127
+ }
128
+ let match = false
129
+ _.each(productVariants.value, (pv) => {
130
+ let pvoptions = pv.options
131
+ .map((pvo) => {
132
+ return pvo.attribute_id + '-' + pvo.value
133
+ })
134
+ .sort()
135
+ if (_.difference(selectedEntries.value, pvoptions).length === 0) {
136
+ match = pv
89
137
  }
90
- },
138
+ })
139
+ if (match) {
140
+ highlight.value = false
141
+ }
142
+ return match
143
+ }
91
144
 
92
- watch: {
93
- product: function (val) {
94
- this.productVariantOptions = this.product.variant_options
95
- this.productVariants = this.product.variants
96
- this.setOptionCombinations()
145
+ function removeUnfitting(optionValue, optionId) {
146
+ let akv = optionId + '-' + optionValue
147
+ for (let selectedKey in selectedOptions) {
148
+ if (selectedKey === optionId) {
149
+ continue
97
150
  }
98
- },
99
-
100
- computed: {
101
- selectedEntries() {
102
- return Object.entries(this.selectedOptions)
103
- .map((so) => so[0] + '-' + so[1])
104
- .sort()
105
- },
106
- descriptionById: function() {
107
- return (id) => this.itemById(id).description;
151
+ let kv = selectedKey + '-' + selectedOptions[selectedKey]
152
+ let fits = _.any(optionCombinations.value, (c) => {
153
+ return c.includes(kv) && c.includes(akv)
154
+ })
155
+ if (fits === false) {
156
+ delete selectedOptions[selectedKey]
108
157
  }
109
- },
158
+ }
159
+ }
110
160
 
111
- methods: {
112
- formatMoney,
113
-
114
- setOptionCombinations() {
115
- let allOptions = _.pluck(this.productVariants, 'options')
116
- allOptions.forEach((options) => {
117
- let v = []
118
- options.forEach((o) => {
119
- v.push(o.attribute_id + '-' + o.value)
120
- })
121
- this.optionCombinations.push(v)
122
- })
123
- //console.log('combinations ', this.optionCombinations)
124
- },
125
-
126
- setFittingUnselected() {
127
- let fitting = []
128
- this.fittingUnselected = []
129
- if (this.selectedEntries.length === 1) {
130
- let selectedKey = parseInt(Object.keys(this.selectedOptions)[0])
131
- let selectedKeyOptionValues = _.findWhere(this.productVariantOptions, { id: selectedKey }).values
132
- //console.log('selectedKeyOptionValues ', selectedKeyOptionValues)
133
- fitting = selectedKeyOptionValues.map((skov) => selectedKey + '-' + skov)
134
- }
135
- this.selectedEntries.forEach((so) => {
136
- fitting.push(_.filter(this.optionCombinations, (c) => c.includes(so)))
137
- })
138
- //console.log('fitting ', _.uniq(_.flatten(fitting)))
139
- this.fittingUnselected = _.uniq(_.flatten(fitting))
140
- },
141
-
142
- getMatchingVariant() {
143
- //console.log(this.selectedEntries.length, this.productVariantOptions.length)
144
- if (this.selectedEntries.length !== this.productVariantOptions.length) {
145
- return false
146
- }
147
- //console.log('getMatchingVariant:')
148
- let match = false
149
- _.each(this.productVariants, (pv) => {
150
- let pvoptions = pv.options
151
- .map((pvo) => {
152
- return pvo.attribute_id + '-' + pvo.value
153
- })
154
- .sort()
155
- //console.log('diff ', selectedEntries, pvoptions, _.difference(selectedEntries, pvoptions))
156
- if (_.difference(this.selectedEntries, pvoptions).length === 0) {
157
- match = pv
158
- }
159
- })
160
- if (match) {
161
- this.highlight = false
162
- }
163
- //console.log('match', match)
164
- return match
165
- },
166
-
167
- removeUnfitting(optionValue, optionId) {
168
- let akv = optionId + '-' + optionValue
169
- for (let selectedKey in this.selectedOptions) {
170
- if (selectedKey === optionId) {
171
- continue
172
- }
173
- let kv = selectedKey + '-' + this.selectedOptions[selectedKey]
174
- //console.log('removeUnfitting: ', akv, kv, this.optionCombinations)
175
- let fits = _.any(this.optionCombinations, (c) => {
176
- return c.includes(kv) && c.includes(akv)
177
- })
178
- if (fits === false) {
179
- this.$delete(this.selectedOptions, selectedKey)
180
- }
181
- //console.log('found fits ', fits)
182
- }
183
- },
184
-
185
- optionSelect(optionValue, option) {
186
- //console.log('opt select')this.updateDiscountBadge()
187
- this.selectedVariant = null
188
- this.fittingUnselected = []
189
- this.updateDiscountBadge()
190
- if (this.selectedOptions[option.id] === optionValue) {
191
- this.$delete(this.selectedOptions, option.id)
192
- } else {
193
- this.$set(this.selectedOptions, option.id, optionValue)
194
- }
195
- this.removeUnfitting(optionValue, option.id)
196
- this.selectedVariant = this.getMatchingVariant()
197
- if (!this.selectedVariant) {
198
- this.setFittingUnselected()
199
- } else {
200
- this.updateDiscountBadge()
201
- }
202
- this.emitEvents()
203
- },
204
-
205
- isOptionDisabled(opt) {
206
- if (this.selectedEntries.length > 0 && this.selectedEntries.length < this.productVariantOptions.length) {
207
- return !this.fittingUnselected.includes(opt)
208
- } else {
209
- return false
210
- }
211
- },
161
+ function optionSelect(optionValue, option) {
162
+ selectedVariant.value = null
163
+ fittingUnselected.value = []
164
+ updateDiscountBadge()
165
+ if (selectedOptions[option.id] === optionValue) {
166
+ delete selectedOptions[option.id]
167
+ } else {
168
+ selectedOptions[option.id] = optionValue
169
+ }
170
+ removeUnfitting(optionValue, option.id)
171
+ selectedVariant.value = getMatchingVariant()
172
+ if (!selectedVariant.value) {
173
+ setFittingUnselected()
174
+ } else {
175
+ updateDiscountBadge()
176
+ }
177
+ emitEvents()
178
+ }
212
179
 
213
- setSelectedVariant(variant) {
214
- if(!variant) {
215
- return
216
- }
217
- console.log('preselecting variant', variant)
218
- this.selectedVariant = variant
219
- this.selectedVariant.options.forEach((vo) => {
220
- this.$set(this.selectedOptions, vo.attribute_id, vo.value)
221
- })
180
+ function isOptionDisabled(opt) {
181
+ const hasPartialSelection = selectedEntries.value.length > 0 && selectedEntries.value.length < productVariantOptions.value.length
182
+ if (!hasPartialSelection) {
183
+ return false
184
+ }
222
185
 
223
- this.updateDiscountBadge(variant)
186
+ // If combinations are not built yet, keep options enabled to avoid blocking interaction
187
+ if (!optionCombinations.value.length || !fittingUnselected.value.length) {
188
+ return false
189
+ }
224
190
 
225
- this.$nextTick(() => {
226
- this.emitEvents('preselect')
227
- })
228
- },
191
+ return !fittingUnselected.value.includes(opt)
192
+ }
229
193
 
230
- updateDiscountBadge() {
231
- let badge = document.querySelector(this.badgeSelector)
232
- if(!badge) {
233
- return
234
- }
235
- badge.style.visibility = 'hidden';
236
- if(!this.selectedVariant) {
237
- return
238
- }
239
- let discountPercent = Math.round((this.selectedVariant.compare_price - this.selectedVariant.price)/this.selectedVariant.compare_price * 100, 0)
194
+ function setSelectedVariant(variant) {
195
+ if(!variant) {
196
+ return
197
+ }
198
+ console.log('preselecting variant', variant)
199
+ selectedVariant.value = variant
200
+ selectedVariant.value.options.forEach((vo) => {
201
+ selectedOptions[vo.attribute_id] = vo.value
202
+ })
240
203
 
241
- if(discountPercent > 0) {
242
- badge.style.visibility = 'visible';
243
- badge.textContent = `-${discountPercent}%`
244
- }
245
- },
204
+ updateDiscountBadge(variant)
246
205
 
247
- updateOverridePriceNotification() {
248
- let opActiveContainer = document.querySelector(this.overridePriceNotificationSelector)
249
- if(!opActiveContainer) {
250
- return
251
- }
252
- opActiveContainer.textContent = ''
206
+ nextTick(() => {
207
+ emitEvents('preselect')
208
+ })
209
+ }
253
210
 
254
- if(!this.selectedVariant) {
255
- return
256
- }
211
+ function updateDiscountBadge() {
212
+ if (typeof document === 'undefined') {
213
+ return
214
+ }
215
+ let badge = document.querySelector(props.badgeSelector)
216
+ if(!badge) {
217
+ return
218
+ }
219
+ badge.style.visibility = 'hidden';
220
+ if(!selectedVariant.value) {
221
+ return
222
+ }
223
+ let discountPercent = Math.round((selectedVariant.value.compare_price - selectedVariant.value.price)/selectedVariant.value.compare_price * 100, 0)
257
224
 
258
- if(this.selectedVariant.override_price_active) {
259
- opActiveContainer.textContent = 'Trajanje akcije od ' +
260
- formatDate(new Date(this.selectedVariant.override_start_at), 'DD.MM.YYYY HH:mm') +
261
- ' do ' +
262
- formatDate(new Date(this.selectedVariant.override_stop_at), 'DD.MM.YYYY HH:mm')
263
- }
264
- },
225
+ if(discountPercent > 0) {
226
+ badge.style.visibility = 'visible';
227
+ badge.textContent = `-${discountPercent}%`
228
+ }
229
+ }
265
230
 
266
- updateDiscountInfo() {
267
- let discountInfoContainer = document.querySelector(this.discountInfoSelector)
268
- if(!discountInfoContainer) {
269
- return
270
- }
271
- let discountMessageContainer = discountInfoContainer.querySelector('.discount-message')
272
-
273
- discountInfoContainer.classList.add('is-hidden')
274
- discountMessageContainer.textContent = ''
231
+ function updateOverridePriceNotification() {
232
+ if (typeof document === 'undefined') {
233
+ return
234
+ }
235
+ let opActiveContainer = document.querySelector(props.overridePriceNotificationSelector)
236
+ if(!opActiveContainer) {
237
+ return
238
+ }
239
+ opActiveContainer.textContent = ''
275
240
 
276
- if(!this.selectedVariant) {
277
- return
278
- }
241
+ if(!selectedVariant.value) {
242
+ return
243
+ }
279
244
 
280
- const productDiscountInfo = window.wkl_product_discount_info
245
+ if(selectedVariant.value.override_price_active) {
246
+ opActiveContainer.textContent = 'Trajanje akcije od ' +
247
+ formatDate(new Date(selectedVariant.value.override_start_at), 'DD.MM.YYYY HH:mm') +
248
+ ' do ' +
249
+ formatDate(new Date(selectedVariant.value.override_stop_at), 'DD.MM.YYYY HH:mm')
250
+ }
251
+ }
281
252
 
282
- const variantDiscountInfo = productDiscountInfo.find(pdi => pdi.product_id == this.selectedVariant.id)
253
+ function updateDiscountInfo() {
254
+ if (typeof document === 'undefined' || typeof window === 'undefined') {
255
+ return
256
+ }
257
+ let discountInfoContainer = document.querySelector(props.discountInfoSelector)
258
+ if(!discountInfoContainer) {
259
+ return
260
+ }
261
+ let discountMessageContainer = discountInfoContainer.querySelector('.discount-message')
262
+
263
+ discountInfoContainer.classList.add('is-hidden')
264
+ discountMessageContainer.textContent = ''
283
265
 
284
- if(variantDiscountInfo) {
285
- discountInfoContainer.classList.remove('is-hidden')
286
- if(variantDiscountInfo.coupon_applied) {
287
- discountMessageContainer.textContent = `U korpi će vam biti obračunat popust od ${this.formatMoney(variantDiscountInfo.discount_amount)} RSD`
288
- } else {
289
- if(variantDiscountInfo.description.trim() !== '') {
290
- discountMessageContainer.innerHTML = `<p>${variantDiscountInfo.description}</p><hr>`
291
- }
292
- discountMessageContainer.innerHTML += `Iskoristi promo kod <strong>${variantDiscountInfo.coupon_code}</strong> za popust od <strong>${this.formatMoney(variantDiscountInfo.discount_amount)} RSD</strong>`
293
- }
294
- }
266
+ if(!selectedVariant.value) {
267
+ return
268
+ }
295
269
 
296
- },
270
+ const productDiscountInfo = window.wkl_product_discount_info
297
271
 
298
- getVariantByOption(optionId, optionValue) {
299
- if (this.productVariantOptions.length !== 1) {
300
- return {}
301
- }
302
- let match = {}
303
- _.each(this.productVariants, (pv) => {
304
- if(pv.in_stock && pv.options[0].attribute_id === optionId && pv.options[0].value === optionValue) {
305
- match = pv
306
- }
307
- })
308
- return match
309
- },
272
+ const variantDiscountInfo = productDiscountInfo.find(pdi => pdi.product_id == selectedVariant.value.id)
310
273
 
311
- getVariantFromProp() {
312
- if(!this.variantId) {
313
- return
274
+ if(variantDiscountInfo) {
275
+ discountInfoContainer.classList.remove('is-hidden')
276
+ if(variantDiscountInfo.coupon_applied) {
277
+ discountMessageContainer.textContent = `U korpi će vam biti obračunat popust od ${formatMoney(variantDiscountInfo.discount_amount)} RSD`
278
+ } else {
279
+ if(variantDiscountInfo.description.trim() !== '') {
280
+ discountMessageContainer.innerHTML = `<p>${variantDiscountInfo.description}</p><hr>`
314
281
  }
315
- let variant = _.findWhere(this.productVariants, { id: this.variantId })
316
- if (!variant) {
317
- return
318
- }
319
- return variant
320
- },
282
+ discountMessageContainer.innerHTML += `Iskoristi promo kod <strong>${variantDiscountInfo.coupon_code}</strong> za popust od <strong>${formatMoney(variantDiscountInfo.discount_amount)} RSD</strong>`
283
+ }
284
+ }
285
+ }
321
286
 
322
- getVariantFromURL() {
323
- let variant_id = parseInt(new URL(window.location.href).searchParams.get('variant'))
324
- if (!variant_id) {
325
- return
326
- }
327
- //console.log('getVariantFromURL', variant_id, this.productVariants)
328
- let variant = _.findWhere(this.productVariants, { id: variant_id })
329
- if (!variant || !variant.in_stock) {
330
- return
331
- }
332
- return variant
333
- },
334
-
335
- preselect() {
336
- let propVariant = this.getVariantFromProp()
337
- if(propVariant) {
338
- this.setSelectedVariant(propVariant)
339
- return
340
- }
341
- let urlVariant = this.getVariantFromURL()
342
-
343
- if(urlVariant) {
344
- this.setSelectedVariant(urlVariant)
345
- } else {
346
- let inStockVariants = _.sortBy(
347
- _.filter(this.productVariants, (item) => item.in_stock && item.price > 0),
348
- 'price'
349
- )
350
-
351
- if (inStockVariants.length === 0) {
352
- return
353
- }
354
- if (this.render === 'pricetags' || inStockVariants.length === 1) {
355
- this.setSelectedVariant(inStockVariants[0])
356
- } else {
357
- let discounted = inStockVariants.find(isv => isv.price !== isv.compare_price);
358
- if(discounted) {
359
- this.setSelectedVariant(discounted)
360
- } else {
361
- this.setSelectedVariant(inStockVariants[0])
362
- }
363
- }
364
- }
287
+ function getVariantByOption(optionId, optionValue) {
288
+ if (productVariantOptions.value.length !== 1) {
289
+ return {}
290
+ }
291
+ let match = {}
292
+ _.each(productVariants.value, (pv) => {
293
+ if(pv.in_stock && pv.options[0].attribute_id === optionId && pv.options[0].value === optionValue) {
294
+ match = pv
295
+ }
296
+ })
297
+ return match
298
+ }
365
299
 
366
- },
300
+ function getVariantFromProp() {
301
+ if(!props.variantId) {
302
+ return
303
+ }
304
+ let variant = _.findWhere(productVariants.value, { id: props.variantId })
305
+ if (!variant) {
306
+ return
307
+ }
308
+ return variant
309
+ }
367
310
 
368
- emitEvents(context='') {
369
- if (!this.selectedVariant) {
370
- this.$bus.$emit('selectVariant', false)
371
- this.$bus.$emit('updateSKU', '')
372
- return
373
- }
311
+ function getVariantFromURL() {
312
+ if (typeof window === 'undefined') {
313
+ return
314
+ }
315
+ let variant_id = parseInt(new URL(window.location.href).searchParams.get('variant'))
316
+ if (!variant_id) {
317
+ return
318
+ }
319
+ let variant = _.findWhere(productVariants.value, { id: variant_id })
320
+ if (!variant || !variant.in_stock) {
321
+ return
322
+ }
323
+ return variant
324
+ }
374
325
 
375
- this.$bus.$emit('selectVariant', this.selectedVariant.id)
376
- this.$bus.$emit('changePhoto', this.selectedVariant.default_image_id)
377
- this.$bus.$emit('updateSKU', this.selectedVariant.sku || this.selectedVariant.id)
378
- if(context !== 'preselect') {
379
- this.$bus.$emit('updatePrice', this.selectedVariant.price, this.selectedVariant.compare_price)
380
- }
381
- this.updateOverridePriceNotification()
382
- this.updateDiscountInfo()
326
+ function preselect() {
327
+ let propVariant = getVariantFromProp()
328
+ if(propVariant) {
329
+ setSelectedVariant(propVariant)
330
+ return
331
+ }
332
+ let urlVariant = getVariantFromURL()
333
+
334
+ if(urlVariant) {
335
+ setSelectedVariant(urlVariant)
336
+ } else {
337
+ let inStockVariants = _.sortBy(
338
+ _.filter(productVariants.value, (item) => item.in_stock && item.price > 0),
339
+ 'price'
340
+ )
341
+
342
+ if (inStockVariants.length === 0) {
343
+ return
383
344
  }
384
- },
385
-
386
- mounted() {
387
- if (this.product.id) {
388
- this.productVariantOptions = this.product.variant_options
389
- this.productVariants = this.product.variants
390
- } else if (window.wkl_product) {
391
- this.$emit('update', window.wkl_product)
345
+ if (props.render === 'pricetags' || inStockVariants.length === 1) {
346
+ setSelectedVariant(inStockVariants[0])
347
+ } else {
348
+ let discounted = inStockVariants.find(isv => isv.price !== isv.compare_price);
349
+ if(discounted) {
350
+ setSelectedVariant(discounted)
351
+ } else {
352
+ setSelectedVariant(inStockVariants[0])
353
+ }
392
354
  }
355
+ }
356
+ }
393
357
 
394
- this.$bus.$on('noVariantSelected', () => {
395
- this.highlight = true
396
- })
358
+ function emitEvents(context='') {
359
+ if (!selectedVariant.value) {
360
+ $bus.emit('selectVariant', false)
361
+ $bus.emit('updateSKU', '')
362
+ return
363
+ }
397
364
 
398
- this.$nextTick(() => {
399
- this.preselect()
400
- this.setOptionCombinations()
401
- //this.setSelectedVariant(this.getVariantFromURL())
402
- })
365
+ $bus.emit('selectVariant', selectedVariant.value.id)
366
+ $bus.emit('changePhoto', selectedVariant.value.default_image_id)
367
+ $bus.emit('updateSKU', selectedVariant.value.sku || selectedVariant.value.id)
368
+ if(context !== 'preselect') {
369
+ $bus.emit('updatePrice', selectedVariant.value.price, selectedVariant.value.compare_price)
403
370
  }
371
+ updateOverridePriceNotification()
372
+ updateDiscountInfo()
404
373
  }
374
+
375
+ const onNoVariantSelected = () => {
376
+ highlight.value = true
377
+ }
378
+
379
+ // Lifecycle
380
+ onMounted(() => {
381
+ if (props.product.id) {
382
+ productVariantOptions.value = props.product.variant_options
383
+ productVariants.value = props.product.variants
384
+ } else if (typeof window !== 'undefined' && window.wkl_product) {
385
+ emit('update', window.wkl_product)
386
+ }
387
+
388
+ $bus.on('noVariantSelected', onNoVariantSelected)
389
+
390
+ nextTick(() => {
391
+ preselect()
392
+ setOptionCombinations()
393
+ })
394
+ })
395
+
396
+ onBeforeUnmount(() => {
397
+ $bus.off('noVariantSelected', onNoVariantSelected)
398
+ })
405
399
  </script>