@wikala/spmkt 2.31.1 → 3.0.0-beta.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/MIGRATION_GUIDE.md +261 -0
- package/api/product.js +1 -0
- package/api/request.js +9 -4
- package/api/user.js +1 -1
- package/components/Account/AccountDashboard.vue +101 -101
- package/components/Account/AccountStore.js +57 -31
- package/components/Account/AffiliateReport.vue +56 -60
- package/components/Account/{OrderDetail.vue → Orders/OrderDetail.vue} +44 -30
- package/components/Account/Orders/Orders.vue +124 -0
- package/components/Account/{AccountSettings.vue → Settings/AccountSettings.vue} +4 -4
- package/components/Account/Settings/ChangeEmail.vue +136 -0
- package/components/Account/Settings/ChangeName.vue +82 -0
- package/components/Account/Settings/ChangePassword.vue +91 -0
- package/components/Address/Address.vue +38 -57
- package/components/Address/AddressBook.vue +77 -57
- package/components/Address/AddressSelect.vue +94 -87
- package/components/Address/Edit.vue +253 -265
- package/components/Address/PostalCode.vue +22 -21
- package/components/AgeGate.vue +11 -5
- package/components/Auth/Login.vue +62 -44
- package/components/Auth/Register.vue +82 -60
- package/components/Auth/ResetPassword.vue +45 -30
- package/components/Cart/AgeVerification/AgeChecker.vue +3 -3
- package/components/Cart/CartBadge.vue +15 -4
- package/components/Cart/CartBox.vue +19 -11
- package/components/Cart/CartItem.vue +3 -3
- package/components/Cart/CartMode.vue +6 -5
- package/components/Cart/CartPreview.vue +24 -18
- package/components/Cart/CreditCard/Everyware.vue +10 -10
- package/components/Cart/CreditCard/ExtendedCreditCard.vue +5 -5
- package/components/Cart/CreditCard/SquarePay.vue +18 -16
- package/components/Cart/CreditCard/StandardCreditCard.vue +9 -9
- package/components/Cart/Delivery/Delivery.vue +16 -12
- package/components/Cart/Delivery/DeliveryAddress.vue +1 -1
- package/components/Cart/Delivery/DeliveryMethods.vue +1 -1
- package/components/Cart/Delivery/DeliveryOptions.vue +15 -9
- package/components/Cart/Delivery/DeliveryTypes.vue +8 -5
- package/components/Cart/Delivery/ReservationSlots.vue +14 -8
- package/components/Cart/Disclaimer.vue +1 -1
- package/components/Cart/OrderConfirmation.vue +1 -1
- package/components/Cart/Payment/Payment.vue +37 -33
- package/components/Cart/Payment/PaymentMethods.vue +6 -4
- package/components/Cart/ReviewAndSubmit.vue +9 -7
- package/components/Cart/ShoppingCart.vue +42 -31
- package/components/Cart/Store/actions.js +1 -1
- package/components/Cart/Store/getters.js +2 -1
- package/components/Cart/Store/index.js +1 -1
- package/components/Cart/Store/mutations.js +7 -5
- package/components/Cart/UserIdentity.vue +1 -1
- package/components/Category/CategoryFilter.vue +128 -114
- package/components/Category/CategorySort.vue +44 -32
- package/components/Category/LoadMore.vue +39 -23
- package/components/DeliverTo.vue +10 -15
- package/components/DeliveryNotice.vue +72 -68
- package/components/DobInput.vue +23 -23
- package/components/Gmaps/GmapsAutocomplete.vue +139 -78
- package/components/Gmaps/GmapsLocations.vue +1 -1
- package/components/Gmaps/GmapsSingleLocation.vue +121 -87
- package/components/ModalContainer/ModalContainer.vue +12 -9
- package/components/ModalContainer/index.js +61 -18
- package/components/Product/AddToCart.vue +237 -221
- package/components/Product/BoxAddToCart.vue +114 -86
- package/components/Product/Compare.vue +68 -48
- package/components/Product/CompareBox.vue +128 -123
- package/components/Product/Lookup.vue +92 -65
- package/components/Product/Photo.vue +105 -66
- package/components/Product/Price.vue +64 -43
- package/components/Product/ProductAutocomplete.vue +52 -57
- package/components/Product/ProductBox.vue +61 -38
- package/components/Product/ProductImages.vue +83 -86
- package/components/Product/Quantity.vue +115 -53
- package/components/Product/QuickView.vue +52 -45
- package/components/Product/RelatedProducts.vue +88 -23
- package/components/Product/SKU.vue +27 -8
- package/components/Product/Variants.vue +335 -341
- package/components/Product/reviews-questions/ProductQuestions.vue +226 -198
- package/components/Product/reviews-questions/ProductReviews.vue +122 -107
- package/components/Product/reviews-questions/Review.vue +54 -59
- package/components/Product/reviews-questions/ReviewForm.vue +222 -170
- package/components/Product/reviews-questions/ReviewImages.vue +197 -216
- package/components/Product/reviews-questions/Vote.vue +83 -57
- package/components/QuantityInput.vue +18 -8
- package/components/RangeInput.vue +15 -8
- package/components/Recaptcha.vue +8 -1
- package/components/SelectShippingCountry.vue +81 -62
- package/components/TimedOffer.vue +59 -74
- package/composables/globals.js +53 -0
- package/config.js +5 -2
- package/index.js +41 -10
- package/install.js +75 -0
- package/locales/en.json +2 -1
- package/locales/sr.json +2 -1
- package/package.json +43 -30
- package/utils/directives.js +28 -45
- package/utils/event-bus.js +56 -0
- package/utils/filters.js +24 -7
- package/utils/{gmaps.js → google/gmaps.js} +43 -10
- package/utils/{google-analytics-eec.js → google/google-analytics-eec.js} +7 -7
- package/babel.config.js +0 -5
- package/components/Account/ChangeEmail.vue +0 -133
- package/components/Account/ChangeName.vue +0 -92
- package/components/Account/ChangePassword.vue +0 -94
- package/components/Account/CreditCards.vue +0 -18
- package/components/Account/Orders.vue +0 -110
- package/components/Account/Settings.vue +0 -18
- package/components/Cart/Delivery/DeliveryAddressGuest.spec.js +0 -128
- package/components/Cart/Delivery/DeliveryTypes.spec.js +0 -83
- package/components/Cart/PCIBadge/SecurityMetrics.vue +0 -11
- package/components/Instagram.vue +0 -49
- package/components/ProductImageModal.vue +0 -41
- package/jest.config.js +0 -16
- package/test/e2e/.babelrc.js +0 -8
- package/test/e2e/.eslintrc.js +0 -11
- package/test/e2e/accAuth.spec.js +0 -64
- package/test/e2e/ageGate.spec.js +0 -26
- package/test/e2e/checkout.spec.js +0 -106
- package/test/e2e/compare.spec.js +0 -52
- package/test/e2e/config/data.js +0 -21
- package/test/e2e/config/routes.js +0 -11
- package/test/e2e/region.spec.js +0 -46
- package/test/e2e/search.spec.js +0 -32
- package/tests/vueBuefy.js +0 -4
- 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-
|
|
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
|
-
<
|
|
22
|
-
<
|
|
23
|
-
<span class="price-old" v-if="
|
|
24
|
-
<span class="price">{{ formatMoney(
|
|
25
|
-
</
|
|
26
|
-
</
|
|
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
|
|
35
|
+
<script setup>
|
|
36
|
+
import { ref, reactive, computed, watch, onMounted, onBeforeUnmount, nextTick } from 'vue'
|
|
36
37
|
import { formatMoney } from '../../utils/filters'
|
|
38
|
+
import { useBus } from '../../composables/globals'
|
|
39
|
+
import _ from 'underscore'
|
|
37
40
|
import formatDate from 'intl-dateformat'
|
|
38
41
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
})
|
|
228
|
-
},
|
|
191
|
+
return !fittingUnselected.value.includes(opt)
|
|
192
|
+
}
|
|
229
193
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
242
|
-
badge.style.visibility = 'visible';
|
|
243
|
-
badge.textContent = `-${discountPercent}%`
|
|
244
|
-
}
|
|
245
|
-
},
|
|
204
|
+
updateDiscountBadge(variant)
|
|
246
205
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
opActiveContainer.textContent = ''
|
|
206
|
+
nextTick(() => {
|
|
207
|
+
emitEvents('preselect')
|
|
208
|
+
})
|
|
209
|
+
}
|
|
253
210
|
|
|
254
|
-
|
|
255
|
-
|
|
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
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
},
|
|
225
|
+
if(discountPercent > 0) {
|
|
226
|
+
badge.style.visibility = 'visible';
|
|
227
|
+
badge.textContent = `-${discountPercent}%`
|
|
228
|
+
}
|
|
229
|
+
}
|
|
265
230
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
277
|
-
|
|
278
|
-
|
|
241
|
+
if(!selectedVariant.value) {
|
|
242
|
+
return
|
|
243
|
+
}
|
|
279
244
|
|
|
280
|
-
|
|
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
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
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
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
358
|
+
function emitEvents(context='') {
|
|
359
|
+
if (!selectedVariant.value) {
|
|
360
|
+
$bus.emit('selectVariant', false)
|
|
361
|
+
$bus.emit('updateSKU', '')
|
|
362
|
+
return
|
|
363
|
+
}
|
|
397
364
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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>
|