@wikala/spmkt 2.31.0 → 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/Coupon.vue +4 -5
- 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
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script>
|
|
8
|
+
import { ref, onMounted } from 'vue'
|
|
9
|
+
import { useBuefy, useT } from '../../composables/globals'
|
|
8
10
|
import config from '../../config'
|
|
9
|
-
import
|
|
10
|
-
import GoogleAnalyticsEEC from '../../utils/google-analytics-eec.js'
|
|
11
|
-
|
|
11
|
+
import GoogleAnalyticsEEC from '../../utils/google/google-analytics-eec.js'
|
|
12
12
|
import { request, Cart } from '../../api'
|
|
13
|
+
import { eventBus } from '../../utils/event-bus'
|
|
13
14
|
|
|
14
15
|
export default {
|
|
15
16
|
name: 'BoxAddToCart',
|
|
@@ -21,129 +22,156 @@ export default {
|
|
|
21
22
|
},
|
|
22
23
|
},
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
emits: ['success'],
|
|
26
|
+
|
|
27
|
+
setup(props, { emit }) {
|
|
28
|
+
const $buefy = useBuefy()
|
|
29
|
+
const { t: $t } = useT()
|
|
30
|
+
|
|
31
|
+
// Reactive state
|
|
32
|
+
const loading = ref(false)
|
|
33
|
+
const product = ref({})
|
|
34
|
+
const qty = ref(1)
|
|
35
|
+
const product_id = ref(props.productId)
|
|
36
|
+
|
|
37
|
+
// Methods
|
|
38
|
+
const eecProduct = () => {
|
|
39
|
+
const eecProduct = {
|
|
40
|
+
item_id: product.value.id,
|
|
41
|
+
item_name: product.value.name,
|
|
42
|
+
price: product.value.price,
|
|
43
|
+
item_brand: product.value.brand ? product.value.brand.name : '',
|
|
44
|
+
item_category: product.value?.category?.path.startsWith('/')
|
|
45
|
+
? product.value?.category?.path.substr(1)
|
|
46
|
+
: product.value?.category?.path,
|
|
47
|
+
quantity: parseInt(qty.value, 10)
|
|
41
48
|
}
|
|
42
|
-
//console.log('eecProduct ', eecProduct)
|
|
43
49
|
return eecProduct
|
|
44
|
-
}
|
|
50
|
+
}
|
|
45
51
|
|
|
46
|
-
productDetails() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
const productDetails = () => {
|
|
53
|
+
const prod = eecProduct()
|
|
54
|
+
prod.image_url = product.value.images && product.value.images[0]
|
|
55
|
+
? product.value.images[0].url
|
|
56
|
+
: ''
|
|
57
|
+
return prod
|
|
58
|
+
}
|
|
51
59
|
|
|
52
|
-
variantsInStock() {
|
|
53
|
-
|
|
60
|
+
const variantsInStock = () => {
|
|
61
|
+
const vis = product.value.variants?.filter(variant => {
|
|
54
62
|
return variant.in_stock
|
|
55
|
-
})
|
|
63
|
+
}) || []
|
|
56
64
|
return vis.length
|
|
57
|
-
}
|
|
65
|
+
}
|
|
58
66
|
|
|
59
|
-
async
|
|
67
|
+
const updateCart = async () => {
|
|
60
68
|
try {
|
|
61
|
-
|
|
62
|
-
mode:
|
|
63
|
-
id:
|
|
64
|
-
qty:
|
|
69
|
+
const response = await Cart.update({
|
|
70
|
+
mode: 'add',
|
|
71
|
+
id: product.value.id,
|
|
72
|
+
qty: qty.value
|
|
65
73
|
})
|
|
66
|
-
|
|
74
|
+
|
|
67
75
|
if (response.data) {
|
|
68
|
-
|
|
76
|
+
eventBus.emit('updateCart', response.data)
|
|
69
77
|
} else {
|
|
70
|
-
throw new Error(
|
|
78
|
+
throw new Error($t('cart.updateCartErrorUnknown'))
|
|
71
79
|
}
|
|
72
80
|
return response.data
|
|
73
81
|
} catch (error) {
|
|
74
82
|
if (!error.message) {
|
|
75
|
-
error.message =
|
|
83
|
+
error.message = $t('cart.updateCartError', error.status)
|
|
76
84
|
}
|
|
77
|
-
|
|
78
|
-
title:
|
|
85
|
+
$buefy.dialog.alert({
|
|
86
|
+
title: $t('global.error'),
|
|
79
87
|
message: error.message,
|
|
80
88
|
confirmText: 'OK'
|
|
81
89
|
})
|
|
82
90
|
} finally {
|
|
83
|
-
|
|
91
|
+
loading.value = false
|
|
84
92
|
}
|
|
85
|
-
}
|
|
93
|
+
}
|
|
86
94
|
|
|
87
|
-
async
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
const addToCart = async () => {
|
|
96
|
+
loading.value = true
|
|
97
|
+
const cartResponse = await updateCart()
|
|
90
98
|
if (cartResponse) {
|
|
91
|
-
|
|
92
|
-
|
|
99
|
+
emit('success')
|
|
100
|
+
eventBus.emit('addToCart', productDetails())
|
|
93
101
|
if (!!window.google_tag_manager) {
|
|
94
|
-
GoogleAnalyticsEEC.addToCart(
|
|
95
|
-
|
|
102
|
+
GoogleAnalyticsEEC.addToCart(eecProduct(), () => {
|
|
103
|
+
loading.value = false
|
|
96
104
|
})
|
|
97
105
|
}
|
|
98
106
|
}
|
|
99
|
-
}
|
|
107
|
+
}
|
|
100
108
|
|
|
101
|
-
async
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
const setProduct = async () => {
|
|
110
|
+
product.value = {}
|
|
111
|
+
try {
|
|
112
|
+
const resp = await request({
|
|
113
|
+
// The storefront's products/{id} route; the API one is admin-only
|
|
104
114
|
baseURL: config.BASE_URL,
|
|
105
|
-
url: '/products/' +
|
|
115
|
+
url: '/products/' + product_id.value
|
|
106
116
|
})
|
|
107
|
-
|
|
108
|
-
|
|
117
|
+
product.value = resp.data.product_resource || {}
|
|
118
|
+
} catch (e) {
|
|
119
|
+
// The request helper rejects on HTTP errors and timeouts. Leave the product empty
|
|
120
|
+
// so handleClick's product id check stops instead of throwing
|
|
121
|
+
console.error('Cannot get product', e)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
109
124
|
|
|
110
|
-
async
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
await this.setProduct()
|
|
125
|
+
const handleClick = async (e) => {
|
|
126
|
+
const btn = e.target
|
|
127
|
+
btn.classList.add('is-loading')
|
|
115
128
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.product_id = this.product.variants.find(variant => variant.in_stock).id
|
|
122
|
-
await this.setProduct();
|
|
129
|
+
try {
|
|
130
|
+
await setProduct()
|
|
131
|
+
|
|
132
|
+
if (!product.value.id) {
|
|
133
|
+
return
|
|
123
134
|
}
|
|
124
135
|
|
|
125
|
-
if(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
confirmText: 'Ok',
|
|
130
|
-
type: 'is-success',
|
|
131
|
-
onConfirm: () => {
|
|
132
|
-
window.location.href = '/'+this.product.slug;
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
btn.classList.remove('is-loading')
|
|
136
|
+
if (variantsInStock() === 1) {
|
|
137
|
+
product_id.value = product.value.variants.find(variant => variant.in_stock).id
|
|
138
|
+
await setProduct()
|
|
139
|
+
if (!product.value.id) {
|
|
136
140
|
return
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (variantsInStock() > 1) {
|
|
145
|
+
$buefy.dialog.confirm({
|
|
146
|
+
title: 'Proizvod sa varijantama',
|
|
147
|
+
message: 'Otvorićemo stranicu proizvoda da biste odabrali varijantu.',
|
|
148
|
+
confirmText: 'Ok',
|
|
149
|
+
type: 'is-success',
|
|
150
|
+
ariaRole: 'alertdialog',
|
|
151
|
+
ariaModal: true,
|
|
152
|
+
onConfirm: () => {
|
|
153
|
+
window.location.href = '/' + product.value.slug
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
return
|
|
137
157
|
}
|
|
138
158
|
|
|
139
|
-
|
|
159
|
+
await addToCart()
|
|
160
|
+
} finally {
|
|
140
161
|
btn.classList.remove('is-loading')
|
|
141
|
-
|
|
162
|
+
}
|
|
163
|
+
}
|
|
142
164
|
|
|
143
|
-
|
|
165
|
+
onMounted(() => {
|
|
166
|
+
product_id.value = props.productId
|
|
167
|
+
})
|
|
144
168
|
|
|
145
|
-
|
|
146
|
-
|
|
169
|
+
return {
|
|
170
|
+
loading,
|
|
171
|
+
product,
|
|
172
|
+
qty,
|
|
173
|
+
handleClick
|
|
174
|
+
}
|
|
147
175
|
}
|
|
148
176
|
}
|
|
149
177
|
</script>
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
<tr v-for="(attributes, i) in itemGeneral" :key="i">
|
|
20
20
|
<td>{{ attributes[0].name }}</td>
|
|
21
21
|
<td v-for="(attrs, i) in attributes" :key="i">
|
|
22
|
-
<div v-if="attrs.options">{{ attrs.options
|
|
22
|
+
<div v-if="attrs.options">{{ stringFilter(attrs.options) }}</div>
|
|
23
23
|
<p v-else>{{ attrs.value }}</p>
|
|
24
24
|
</td>
|
|
25
25
|
</tr>
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<tr v-for="(attributes, i) in itemHeating" :key="i">
|
|
30
30
|
<td>{{ attributes[0].name }}</td>
|
|
31
31
|
<td v-for="(attrs, i) in attributes" :key="i">
|
|
32
|
-
<div v-if="attrs.options">{{ attrs.options
|
|
32
|
+
<div v-if="attrs.options">{{ stringFilter(attrs.options) }}</div>
|
|
33
33
|
<p v-else>{{ attrs.value }}</p>
|
|
34
34
|
</td>
|
|
35
35
|
</tr>
|
|
@@ -55,54 +55,74 @@
|
|
|
55
55
|
</div>
|
|
56
56
|
</template>
|
|
57
57
|
|
|
58
|
-
<script>
|
|
59
|
-
import
|
|
58
|
+
<script setup>
|
|
59
|
+
import { ref, onMounted, getCurrentInstance } from 'vue'
|
|
60
|
+
import Lookup from './Lookup.vue'
|
|
60
61
|
import scrollMonitor from 'scrollmonitor'
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
filters: {
|
|
75
|
-
string(value) {
|
|
76
|
-
if (!value) return ''
|
|
77
|
-
value = value.toString()
|
|
78
|
-
return value
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
beforeMount() {
|
|
82
|
-
this.items = window.compare.product
|
|
83
|
-
this.itemGeneral = window.compare.General
|
|
84
|
-
this.itemHeating = window.compare.Heating
|
|
85
|
-
this.itemDimensions = window.compare.Dimensions
|
|
86
|
-
this.itemBattery = window.compare.Battery
|
|
87
|
-
},
|
|
88
|
-
mounted() {
|
|
89
|
-
window.addEventListener(
|
|
90
|
-
'load',
|
|
91
|
-
() => {
|
|
92
|
-
const elToWatch = document.querySelectorAll('.fixedContent')
|
|
93
|
-
|
|
94
|
-
const watcher = scrollMonitor.create(elToWatch)
|
|
95
|
-
watcher.lock()
|
|
96
|
-
|
|
97
|
-
watcher.exitViewport(function () {
|
|
98
|
-
elToWatch.forEach((el) => el.classList.add('scrolled'))
|
|
99
|
-
})
|
|
100
|
-
watcher.enterViewport(function () {
|
|
101
|
-
elToWatch.forEach((el) => el.classList.remove('scrolled'))
|
|
102
|
-
})
|
|
103
|
-
},
|
|
104
|
-
false
|
|
105
|
-
)
|
|
63
|
+
defineOptions({ name: 'ComparePage' })
|
|
64
|
+
|
|
65
|
+
const props = defineProps({
|
|
66
|
+
compareData: {
|
|
67
|
+
type: Object,
|
|
68
|
+
default: () => ({
|
|
69
|
+
product: [],
|
|
70
|
+
General: {},
|
|
71
|
+
Heating: {},
|
|
72
|
+
Dimensions: {},
|
|
73
|
+
Battery: {}
|
|
74
|
+
})
|
|
106
75
|
}
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
// Get global properties
|
|
79
|
+
const instance = getCurrentInstance()
|
|
80
|
+
|
|
81
|
+
// Reactive state
|
|
82
|
+
const items = ref([])
|
|
83
|
+
const itemGeneral = ref({})
|
|
84
|
+
const itemHeating = ref({})
|
|
85
|
+
const itemBattery = ref({})
|
|
86
|
+
const itemDimensions = ref({})
|
|
87
|
+
|
|
88
|
+
// Methods
|
|
89
|
+
const stringFilter = (value) => {
|
|
90
|
+
if (!value) return ''
|
|
91
|
+
value = value.toString()
|
|
92
|
+
return value
|
|
107
93
|
}
|
|
94
|
+
|
|
95
|
+
const initScrollMonitor = () => {
|
|
96
|
+
const elToWatch = document.querySelectorAll('.fixedContent')
|
|
97
|
+
|
|
98
|
+
const watcher = scrollMonitor.create(elToWatch)
|
|
99
|
+
watcher.lock()
|
|
100
|
+
|
|
101
|
+
watcher.exitViewport(function () {
|
|
102
|
+
elToWatch.forEach((el) => el.classList.add('scrolled'))
|
|
103
|
+
})
|
|
104
|
+
watcher.enterViewport(function () {
|
|
105
|
+
elToWatch.forEach((el) => el.classList.remove('scrolled'))
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Lifecycle hooks
|
|
110
|
+
onMounted(() => {
|
|
111
|
+
// Check if compareData prop is provided, otherwise use window.compare
|
|
112
|
+
if (props.compareData && props.compareData.product.length > 0) {
|
|
113
|
+
items.value = props.compareData.product
|
|
114
|
+
itemGeneral.value = props.compareData.General
|
|
115
|
+
itemHeating.value = props.compareData.Heating
|
|
116
|
+
itemDimensions.value = props.compareData.Dimensions
|
|
117
|
+
itemBattery.value = props.compareData.Battery
|
|
118
|
+
} else if (window.compare) {
|
|
119
|
+
items.value = window.compare.product
|
|
120
|
+
itemGeneral.value = window.compare.General
|
|
121
|
+
itemHeating.value = window.compare.Heating
|
|
122
|
+
itemDimensions.value = window.compare.Dimensions
|
|
123
|
+
itemBattery.value = window.compare.Battery
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
window.addEventListener('load', initScrollMonitor, false)
|
|
127
|
+
})
|
|
108
128
|
</script>
|
|
@@ -11,147 +11,152 @@
|
|
|
11
11
|
<img :src="product.image" :alt="product.name" />
|
|
12
12
|
</div>
|
|
13
13
|
</div>
|
|
14
|
-
<button name="compare_button" :disabled="products.length < 2" :class="['button', 'is-primary', { 'is-small':
|
|
14
|
+
<button name="compare_button" :disabled="products.length < 2" :class="['button', 'is-primary', { 'is-small': mq === 'mobile' }]" @click="compare">
|
|
15
15
|
{{ $t('product.compare') }}
|
|
16
16
|
</button>
|
|
17
|
-
<button name="clear_compare" :class="['button', 'btn-close', { 'is-small':
|
|
17
|
+
<button name="clear_compare" :class="['button', 'btn-close', { 'is-small': mq === 'mobile' }]" @click="hideCompareBox"> × </button>
|
|
18
18
|
</div>
|
|
19
19
|
</div>
|
|
20
20
|
</template>
|
|
21
21
|
|
|
22
|
-
<script>
|
|
22
|
+
<script setup>
|
|
23
|
+
import { ref, onMounted, onBeforeUnmount } from 'vue'
|
|
24
|
+
import { useBuefy, useMq, useT } from '../../composables/globals'
|
|
23
25
|
import _ from 'underscore'
|
|
24
26
|
import Cookie from 'js-cookie'
|
|
27
|
+
import { eventBus } from '../../utils/event-bus'
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
defineOptions({ name: 'CompareBox' })
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
attTemplateId: 0,
|
|
33
|
-
products: [],
|
|
34
|
-
viewProducts: true
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
methods: {
|
|
39
|
-
initCompareList() {
|
|
40
|
-
let cCompareList = ''
|
|
41
|
-
try {
|
|
42
|
-
cCompareList = JSON.parse(Cookie.get('compareList'))
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.log('Cannot parse compareList', Cookie.get('compareList'))
|
|
45
|
-
}
|
|
46
|
-
if (cCompareList) {
|
|
47
|
-
this.products = _.compact(cCompareList)
|
|
48
|
-
this.products.forEach((product) => {
|
|
49
|
-
this.setCompareIconStatus(product.id, 'on')
|
|
50
|
-
})
|
|
51
|
-
this.setAttTemplateId()
|
|
52
|
-
}
|
|
53
|
-
},
|
|
31
|
+
const $buefy = useBuefy()
|
|
32
|
+
const { t: $t } = useT()
|
|
33
|
+
const mq = useMq()
|
|
54
34
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
35
|
+
// Reactive state
|
|
36
|
+
const attTemplateId = ref(0)
|
|
37
|
+
const products = ref([])
|
|
38
|
+
const viewProducts = ref(true)
|
|
39
|
+
|
|
40
|
+
// Methods
|
|
41
|
+
const setCompareIconStatus = (product_id, status) => {
|
|
42
|
+
let productIconEl = document.getElementById('prod-compare-' + product_id)
|
|
43
|
+
if (!productIconEl) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
if (status == 'on') {
|
|
47
|
+
productIconEl.classList.add('has-text-info')
|
|
48
|
+
} else {
|
|
49
|
+
productIconEl.classList.remove('has-text-info')
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const initCompareList = () => {
|
|
54
|
+
let cCompareList = ''
|
|
55
|
+
try {
|
|
56
|
+
cCompareList = JSON.parse(Cookie.get('compareList'))
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.log('Cannot parse compareList', Cookie.get('compareList'))
|
|
59
|
+
}
|
|
60
|
+
if (cCompareList) {
|
|
61
|
+
products.value = _.compact(cCompareList)
|
|
62
|
+
products.value.forEach((product) => {
|
|
63
|
+
setCompareIconStatus(product.id, 'on')
|
|
64
|
+
})
|
|
65
|
+
setAttTemplateId()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const setAttTemplateId = () => {
|
|
70
|
+
if (products.value.length > 0) {
|
|
71
|
+
attTemplateId.value = products.value[0]['att_template_id']
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const setProducts = (newProducts) => {
|
|
76
|
+
products.value = newProducts
|
|
77
|
+
setAttTemplateId()
|
|
78
|
+
Cookie.set('compareList', JSON.stringify(products.value), { expires: 1 })
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const addProduct = (product) => {
|
|
82
|
+
if (products.value.length >= 4) {
|
|
83
|
+
$buefy.dialog.alert({
|
|
84
|
+
title: $t('product.compareErrorDialogTitle'),
|
|
85
|
+
message: $t('product.compareErrorMaxProducts'),
|
|
86
|
+
canCancel: ['button', 'escape'],
|
|
87
|
+
confirmText: $t('product.compareErrorDialogConfirm'),
|
|
88
|
+
cancelText: $t('global.cancel'),
|
|
89
|
+
onConfirm: () => {
|
|
90
|
+
compare()
|
|
80
91
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
})
|
|
93
|
+
return false
|
|
94
|
+
}
|
|
95
|
+
products.value.push(product)
|
|
96
|
+
setCompareIconStatus(product.id, 'on')
|
|
97
|
+
setAttTemplateId()
|
|
98
|
+
Cookie.set('compareList', JSON.stringify(products.value), { expires: 1 })
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const compare = () => {
|
|
102
|
+
const productList = products.value.map((el) => el.id)
|
|
103
|
+
window.location.href = `/compare-products?products=${productList}`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const removeProd = (id) => {
|
|
107
|
+
setProducts(_.reject(products.value, (product) => product.id == id))
|
|
108
|
+
setCompareIconStatus(id, 'off')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const clear = () => {
|
|
112
|
+
products.value.forEach((product) => {
|
|
113
|
+
setCompareIconStatus(product.id, 'off')
|
|
114
|
+
})
|
|
115
|
+
setProducts([])
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const hideCompareBox = () => {
|
|
119
|
+
$buefy.dialog.alert({
|
|
120
|
+
title: $t('product.compareCloseDialogTitle'),
|
|
121
|
+
message: $t('product.compareCloseDialogMsg'),
|
|
122
|
+
canCancel: ['button', 'escape'],
|
|
123
|
+
confirmText: $t('product.compareClear'),
|
|
124
|
+
cancelText: $t('global.cancel'),
|
|
125
|
+
onConfirm: () => {
|
|
126
|
+
clear()
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
}
|
|
103
130
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
131
|
+
const handleCompareProduct = (productData) => {
|
|
132
|
+
if (_.findWhere(products.value, { id: productData.id })) {
|
|
133
|
+
removeProd(productData.id)
|
|
134
|
+
} else {
|
|
135
|
+
if (products.value.length > 0 && productData.att_template_id !== attTemplateId.value) {
|
|
136
|
+
$buefy.dialog.alert({
|
|
137
|
+
title: $t('global.error'),
|
|
138
|
+
message: $t('product.compareErrorDifferentCategories'),
|
|
108
139
|
canCancel: ['button', 'escape'],
|
|
109
|
-
confirmText:
|
|
110
|
-
cancelText:
|
|
140
|
+
confirmText: $t('product.compareClear'),
|
|
141
|
+
cancelText: $t('global.cancel'),
|
|
111
142
|
onConfirm: () => {
|
|
112
|
-
|
|
143
|
+
clear()
|
|
144
|
+
addProduct(productData)
|
|
113
145
|
}
|
|
114
146
|
})
|
|
115
|
-
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
setCompareIconStatus(product_id, status) {
|
|
119
|
-
let productIconEl = document.getElementById('prod-compare-' + product_id)
|
|
120
|
-
if (!productIconEl) {
|
|
121
|
-
return false
|
|
122
|
-
}
|
|
123
|
-
if (status == 'on') {
|
|
124
|
-
productIconEl.classList.add('has-text-info')
|
|
125
|
-
} else {
|
|
126
|
-
productIconEl.classList.remove('has-text-info')
|
|
127
|
-
}
|
|
147
|
+
return false
|
|
128
148
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
mounted() {
|
|
132
|
-
this.initCompareList()
|
|
133
|
-
|
|
134
|
-
this.$bus.$on('compareProduct', (productData) => {
|
|
135
|
-
if (_.findWhere(this.products, { id: productData.id })) {
|
|
136
|
-
this.removeProd(productData.id)
|
|
137
|
-
} else {
|
|
138
|
-
if (this.products.length > 0 && productData.att_template_id !== this.attTemplateId) {
|
|
139
|
-
this.$buefy.dialog.alert({
|
|
140
|
-
title: this.$t('global.error'),
|
|
141
|
-
message: this.$t('product.compareErrorDifferentCategories'),
|
|
142
|
-
canCancel: ['button', 'escape'],
|
|
143
|
-
confirmText: this.$t('product.compareClear'),
|
|
144
|
-
cancelText: this.$t('global.cancel'),
|
|
145
|
-
onConfirm: () => {
|
|
146
|
-
this.clear()
|
|
147
|
-
this.addProduct(productData)
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
return false
|
|
151
|
-
}
|
|
152
|
-
this.addProduct(productData)
|
|
153
|
-
}
|
|
154
|
-
})
|
|
149
|
+
addProduct(productData)
|
|
155
150
|
}
|
|
156
151
|
}
|
|
152
|
+
|
|
153
|
+
// Lifecycle hooks
|
|
154
|
+
onMounted(() => {
|
|
155
|
+
initCompareList()
|
|
156
|
+
eventBus.on('compareProduct', handleCompareProduct)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
onBeforeUnmount(() => {
|
|
160
|
+
eventBus.off('compareProduct', handleCompareProduct)
|
|
161
|
+
})
|
|
157
162
|
</script>
|