@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
@@ -6,7 +6,9 @@
6
6
  </template>
7
7
 
8
8
  <script>
9
+ import { ref, onMounted, onUnmounted } from 'vue'
9
10
  import { formatMoney } from '../../utils/filters'
11
+ import { eventBus } from '../../utils/event-bus'
10
12
 
11
13
  export default {
12
14
  name: 'Price',
@@ -19,67 +21,86 @@ export default {
19
21
  }
20
22
  },
21
23
 
22
- data() {
23
- return {
24
- comparePrice: 0,
25
- price: 0,
26
- from: '',
27
- discountPercent: 0
28
- }
29
- },
24
+ setup(props) {
25
+ const comparePrice = ref(0)
26
+ const price = ref(0)
27
+ const from = ref('')
28
+ const discountPercent = ref(0)
30
29
 
31
- methods: {
32
- formatMoney,
33
- refresh(value, compareValue) {
30
+ const refresh = (value, compareValue) => {
34
31
  if (typeof value === 'object' && value.min) {
35
- this.from = 'from'
36
- this.price = value.min
37
- this.comparePrice = compareValue.min
32
+ from.value = 'from'
33
+ price.value = value.min
34
+ comparePrice.value = compareValue.min
38
35
  } else {
39
- this.comparePrice = value
36
+ comparePrice.value = value
40
37
  if (compareValue === undefined) {
41
- this.price = value * (1 - this.discountPercent)
38
+ price.value = value * (1 - discountPercent.value)
42
39
  } else {
43
- this.price = parseFloat(value)
44
- this.comparePrice = parseFloat(compareValue)
40
+ price.value = parseFloat(value)
41
+ comparePrice.value = parseFloat(compareValue)
45
42
  }
46
43
  }
47
44
  }
48
- },
49
45
 
50
- mounted() {
51
- if (typeof this.value !== 'object') {
52
- this.price = parseFloat(this.value)
53
- this.comparePrice = parseFloat(this.compareValue)
46
+ const handleUpdatePrice = (value, compareValue) => {
47
+ if (!value && !compareValue) {
48
+ return
49
+ }
50
+ if (!props.updatable) {
51
+ return false
52
+ }
53
+ refresh(value, compareValue)
54
54
  }
55
55
 
56
- if (typeof this.value === 'object') {
57
- if (Object.entries(this.value).length === 0) {
58
- console.log('Price empty value', this.value)
59
- this.price = NaN
60
- this.comparePrice = NaN
61
- } else {
62
- if (typeof this.value === 'object') {
63
- this.discountPercent = Math.abs(this.value.min - this.compareValue.min) / this.compareValue.min
56
+ onMounted(() => {
57
+ if (typeof props.value !== 'object') {
58
+ price.value = parseFloat(props.value)
59
+ comparePrice.value = parseFloat(props.compareValue)
60
+ }
61
+
62
+ if (typeof props.value === 'object') {
63
+ if (Object.entries(props.value).length === 0) {
64
+ console.log('Price empty value', props.value)
65
+ price.value = NaN
66
+ comparePrice.value = NaN
64
67
  } else {
65
- this.discountPercent = Math.abs(this.value - this.compareValue) / this.compareValue
68
+ if (typeof props.value === 'object') {
69
+ discountPercent.value = Math.abs(props.value.min - props.compareValue.min) / props.compareValue.min
70
+ } else {
71
+ discountPercent.value = Math.abs(props.value - props.compareValue) / props.compareValue
72
+ }
66
73
  }
67
74
  }
68
- }
69
75
 
70
- this.refresh(this.value, this.compareValue)
76
+ refresh(props.value, props.compareValue)
71
77
 
72
- this.$bus.$on('updatePrice', (value, compareValue) => {
73
- if(!value && !compareValue) {
74
- return
75
- }
76
- if (!this.updatable) {
77
- return false
78
- }
79
- this.refresh(value, compareValue)
78
+ eventBus.on('updatePrice', handleUpdatePrice)
79
+ })
80
+
81
+ onUnmounted(() => {
82
+ eventBus.off('updatePrice', handleUpdatePrice)
80
83
  })
84
+
85
+ return {
86
+ comparePrice,
87
+ price,
88
+ from,
89
+ discountPercent,
90
+ formatMoney
91
+ }
81
92
  }
82
93
  }
83
94
  </script>
84
95
 
85
- <style scoped></style>
96
+ <style scoped>
97
+ .price-old {
98
+ text-decoration: line-through;
99
+ margin-right: 0.5rem;
100
+ opacity: 0.7;
101
+ }
102
+
103
+ .price {
104
+ font-weight: 600;
105
+ }
106
+ </style>
@@ -4,7 +4,7 @@
4
4
  name="productSearchForm"
5
5
  action="/search"
6
6
  method="get"
7
- :class="{ active: active == 1 }"
7
+ :class="{ active: active === 1 }"
8
8
  @mouseover="active = 1"
9
9
  @mouseout="active = 0"
10
10
  >
@@ -15,12 +15,12 @@
15
15
  field="name"
16
16
  icon-pack="fas"
17
17
  :data="data"
18
- :value="q ? q : ''"
18
+ v-model="searchQuery"
19
19
  :icon="isFetching ? '' : 'search'"
20
20
  :loading="isFetching"
21
21
  @typing="searchProducts"
22
22
  @select="onSelected"
23
- @keydown.native.enter="onEnter"
23
+ @keydown.enter="onEnter"
24
24
  >
25
25
  <template v-slot="props">
26
26
  <div class="media">
@@ -37,72 +37,67 @@
37
37
  </div>
38
38
  </form>
39
39
  </template>
40
- <script>
40
+ <script setup>
41
+ import { ref, inject, onMounted } from 'vue'
41
42
  import _ from 'underscore'
42
43
  import liveAddEventListener from '../../utils/native-dom'
43
-
44
44
  import { Product } from '../../api'
45
45
 
46
- export default {
47
- name: 'ProductAutocomplete',
48
-
49
- props: {
50
- q: {
51
- type: String,
52
- required: true
53
- },
54
- searchLimit: {
55
- type: String,
56
- required: true
57
- }
58
- },
46
+ defineOptions({ name: 'ProductAutocomplete' })
59
47
 
60
- data() {
61
- return {
62
- data: [],
63
- selected: null,
64
- isFetching: false,
65
- enter: true,
66
- active: 0
67
- }
48
+ const props = defineProps({
49
+ q: {
50
+ type: String,
51
+ required: true
68
52
  },
53
+ searchLimit: {
54
+ type: String,
55
+ required: true
56
+ }
57
+ })
69
58
 
70
- methods: {
71
- searchProducts: _.debounce(function (query_string) {
72
- if (!query_string.length) {
73
- this.data = []
74
- return
75
- }
76
-
77
- this.isFetching = true
59
+ const navigate = inject('navigate', (url) => { window.location.href = url })
78
60
 
79
- Product.search(query_string)
80
- .then((response) => {
81
- let products = response.data.slice(0, this.searchLimit)
82
- this.data = []
83
- products.forEach((item) => this.data.push(item))
84
- })
85
- .finally(() => {
86
- this.isFetching = false
87
- })
88
- }, 250),
61
+ const productSearchForm = ref(null)
62
+ const searchQuery = ref(props.q || '')
63
+ const data = ref([])
64
+ const isFetching = ref(false)
65
+ const enter = ref(true)
66
+ const active = ref(0)
89
67
 
90
- onEnter() {
91
- if (this.enter) {
92
- this.$refs.productSearchForm.submit()
93
- }
94
- },
68
+ const searchProducts = _.debounce((query_string) => {
69
+ if (!query_string.length) {
70
+ data.value = []
71
+ return
72
+ }
95
73
 
96
- onSelected(product) {
97
- this.enter = false
98
- window.location.href = product.url
99
- }
100
- },
74
+ isFetching.value = true
101
75
 
102
- mounted() {
103
- liveAddEventListener('.search-box .icon', 'click', () => {
104
- document.forms.productSearchForm.submit()
76
+ Product.search(query_string)
77
+ .then((response) => {
78
+ let products = response.data.slice(0, props.searchLimit)
79
+ data.value = []
80
+ products.forEach((item) => data.value.push(item))
81
+ })
82
+ .finally(() => {
83
+ isFetching.value = false
105
84
  })
85
+ }, 250)
86
+
87
+ const onEnter = () => {
88
+ if (enter.value) {
89
+ productSearchForm.value.submit()
106
90
  }
107
91
  }
92
+
93
+ const onSelected = (product) => {
94
+ enter.value = false
95
+ navigate(product?.url)
96
+ }
97
+
98
+ onMounted(() => {
99
+ liveAddEventListener('.search-box .icon', 'click', () => {
100
+ document.forms.productSearchForm.submit()
101
+ })
102
+ })
108
103
  </script>
@@ -1,65 +1,88 @@
1
1
  <template>
2
- <div :class="grid">
2
+ <div :class="[{[grid]: true}, 'product-box']">
3
3
  <div class="box">
4
- <a :href="product.slug.split('/').pop()" class="image">
5
- <img :src="product.thumb_url" />
4
+ <a :href="productSlug" class="image">
5
+ <img :src="product.thumb_url" :alt="product.name" />
6
6
  </a>
7
7
  <div class="desc-container">
8
- <a :href="product.slug.split('/').pop()" class="description">{{ product.name }}</a>
8
+ <a :href="productSlug" class="description">{{ product.name }}</a>
9
9
  </div>
10
10
  <div class="stars-reviews">
11
11
  <div class="rating">
12
- <template v-if="product.reviews_count">
13
- <a :href="product.slug + '/reviews'">
14
- <i v-for="sc in starRating(product.rating)" style="margin-right: 3px;" :class="['fas', 'fa-star', sc]"></i>
12
+ <template v-if="hasReviews">
13
+ <a :href="reviewsHref">
14
+ <i
15
+ v-for="(sc, index) in starRating(product.rating)"
16
+ :key="index"
17
+ style="margin-right: 3px;"
18
+ :class="['fas', 'fa-star', sc]"
19
+ ></i>
15
20
  </a>
16
- <a class="review-count" :href="product.slug + '/reviews'">{{product.reviews_count}}</a>
21
+ <a class="review-count" :href="reviewsHref">{{ product.reviews_count }}</a>
17
22
  </template>
18
23
  <template v-else>
19
- <i v-for="sc in starRating(product.rating)" :class="['fas', 'fa-star', sc]"></i>
24
+ <i
25
+ v-for="(sc, index) in starRating(product.rating)"
26
+ :key="index"
27
+ :class="['fas', 'fa-star', sc]"
28
+ ></i>
20
29
  </template>
21
30
  </div>
22
31
  </div>
23
32
  <div class="price-container">
24
- <p class="price">${{ product.price | formatMoney }}</p>
25
- <p v-if="product.price >= 50" class="free-delivery">FREE shipping</p>
33
+ <p class="price">${{ $filters.formatMoney(product.price) }}</p>
34
+ <p v-if="hasFreeShipping" class="free-delivery">FREE shipping</p>
26
35
  </div>
27
36
  </div>
28
37
  </div>
29
38
  </template>
30
39
 
31
- <script>
32
- export default {
33
- name: 'ProductBox',
40
+ <script setup>
41
+ import { computed, toRefs } from 'vue'
34
42
 
35
- props: {
36
- product: {
37
- type: Object,
38
- required: true
39
- },
40
- grid: String
41
- },
42
-
43
- computed: {
44
- getRating() {
45
- return (this.product.rating / 5) * 100
46
- }
43
+ const props = defineProps({
44
+ product: {
45
+ type: Object,
46
+ required: true
47
47
  },
48
+ grid: {
49
+ type: String,
50
+ default: ''
51
+ }
52
+ })
48
53
 
49
- methods: {
50
- starRating(rating) {
51
- let stars = Math.floor(rating)
52
- let halfStars = (rating - stars > .40) ? 1 : 0
53
- let other = 5 - stars - halfStars
54
- let s = ''
55
- s += 'fa-star star-on,'.repeat(stars)
56
- s += 'fa-star-half-alt star-on,'.repeat(halfStars)
57
- s += 'fa-star star-off,'.repeat(other)
54
+ const { product, grid } = toRefs(props)
58
55
 
59
- console.log('star rating ', s.substring(0, s.length-1), s.split(','))
56
+ const productSlug = computed(() => {
57
+ const slug = product.value?.slug || ''
58
+ const segments = slug.split('/').filter(Boolean)
59
+ return segments.length ? segments[segments.length - 1] : ''
60
+ })
60
61
 
61
- return s.substring(0, s.length-1).split(',')
62
- }
62
+ const reviewsHref = computed(() => {
63
+ if (!product.value?.slug) {
64
+ return ''
63
65
  }
66
+ return `${product.value.slug}/reviews`
67
+ })
68
+
69
+ const hasReviews = computed(() => Boolean(product.value?.reviews_count))
70
+
71
+ const hasFreeShipping = computed(() => {
72
+ const price = Number(product.value?.price)
73
+ return !Number.isNaN(price) && price >= 50
74
+ })
75
+
76
+ function starRating(rating = 0) {
77
+ const normalized = Math.max(0, Math.min(5, Number(rating) || 0))
78
+ const stars = Math.floor(normalized)
79
+ const halfStars = normalized - stars > 0.4 ? 1 : 0
80
+ const other = Math.max(0, 5 - stars - halfStars)
81
+ let s = ''
82
+ s += 'fa-star star-on,'.repeat(stars)
83
+ s += 'fa-star-half-alt star-on,'.repeat(halfStars)
84
+ s += 'fa-star star-off,'.repeat(other)
85
+
86
+ return s.substring(0, s.length - 1).split(',').filter(Boolean)
64
87
  }
65
88
  </script>
@@ -5,7 +5,7 @@
5
5
  v-model="activeImage"
6
6
  v-if="product.images.length > 0"
7
7
  :autoplay="false"
8
- :indicator="$mq === 'mobile'"
8
+ :indicator="mq === 'mobile'"
9
9
  :overlay="gallery"
10
10
  @click="switchGallery(true)"
11
11
  @change="changeImage"
@@ -15,14 +15,14 @@
15
15
  <b-carousel-item v-for="(image, i) in product.images" :key="i">
16
16
  <picture class="image">
17
17
  <img
18
- :src="image.url"
18
+ :src="image.url"
19
19
  :srcset="getSrcset(image)"
20
20
  decoding="async"
21
21
  sizes="(min-width: 1420px) 672px, (min-width: 1220px) 576px, (min-width: 1080px) 480px, (min-width: 780px) calc(40.71vw + 48px), 100vw">
22
22
  </picture>
23
23
  </b-carousel-item>
24
24
  <span v-if="gallery" @click="switchGallery(false)" class="modal-close is-large"></span>
25
- <template slot="list" slot-scope="props" v-if="product.images.length > 1">
25
+ <template v-slot:list="props" v-if="product.images.length > 1">
26
26
  <b-carousel-list
27
27
  v-model="props.active"
28
28
  v-bind="al"
@@ -43,98 +43,95 @@
43
43
  </div>
44
44
  </template>
45
45
 
46
- <script>
47
- import _ from 'underscore'
48
- import Photo from './Photo'
46
+ <script setup>
47
+ import { ref, reactive, watch, onMounted, onBeforeUnmount } from 'vue'
48
+ import { useMq } from '../../composables/globals'
49
+ import { eventBus } from '../../utils/event-bus'
49
50
 
50
- export default {
51
- name: 'ProductImages',
52
- components: { Photo },
53
- props: {
54
- product: {
55
- type: Object,
56
- default: function () {
57
- return {}
58
- }
59
- }
60
- },
51
+ defineOptions({ name: 'ProductImages' })
61
52
 
62
- data() {
63
- return {
64
- activeImage: 0,
65
- gallery: false,
66
- al: {
67
- hasGrayscale: true,
68
- itemsToShow: 4,
69
- breakpoints: {
70
- 768: {
71
- hasGrayscale: false,
72
- itemsToShow: 6
73
- },
74
- 960: {
75
- hasGrayscale: false,
76
- itemsToShow: 6
77
- }
78
- }
79
- }
80
- }
81
- },
53
+ const props = defineProps({
54
+ product: {
55
+ type: Object,
56
+ default: () => ({})
57
+ }
58
+ })
82
59
 
83
- watch: {
84
- gallery() {
85
- if (this.gallery) {
86
- console.log('setting items to show')
87
- this.al.breakpoints['960'].itemsToShow = 12
88
- } else {
89
- this.al.breakpoints['960'].itemsToShow = 6
90
- }
91
- }
92
- },
60
+ const emit = defineEmits(['update'])
93
61
 
94
- methods: {
95
- changeImage(e) {
96
- //console.log('changeImage ', e)
97
- },
62
+ const mq = useMq()
98
63
 
99
- getResizedImageUrl(original, resolution) {
100
- let lastDotPosition = original.lastIndexOf('.')
101
- original = original.replace('images', 'thumbs')
102
- return [original.slice(0, lastDotPosition), '-' + resolution, original.slice(lastDotPosition)].join('')
64
+ // Reactive state
65
+ const activeImage = ref(0)
66
+ const gallery = ref(false)
67
+ const al = reactive({
68
+ hasGrayscale: true,
69
+ itemsToShow: 4,
70
+ breakpoints: {
71
+ 768: {
72
+ hasGrayscale: false,
73
+ itemsToShow: 6
103
74
  },
75
+ 960: {
76
+ hasGrayscale: false,
77
+ itemsToShow: 6
78
+ }
79
+ }
80
+ })
104
81
 
105
- getSrcset(imgdata) {
106
- if(!imgdata.available_sizes) return
107
- let srcset = []
108
- imgdata.available_sizes.forEach(asize => {
109
- srcset.push(`${asize.url} ${asize.width}w`)
110
- })
111
- return srcset.join(', ')
112
- },
82
+ // Watchers
83
+ watch(gallery, (newVal) => {
84
+ if (newVal) {
85
+ console.log('setting items to show')
86
+ al.breakpoints['960'].itemsToShow = 12
87
+ } else {
88
+ al.breakpoints['960'].itemsToShow = 6
89
+ }
90
+ })
113
91
 
114
- switchGallery(value) {
115
- if (this.$mq === 'mobile') {
116
- this.gallery = false
117
- return
118
- }
119
- this.gallery = value
120
- if (value) {
121
- document.documentElement.classList.add('is-clipped')
122
- } else {
123
- document.documentElement.classList.remove('is-clipped')
124
- }
125
- }
126
- },
92
+ // Methods
93
+ const changeImage = () => {
94
+ //console.log('changeImage')
95
+ }
127
96
 
128
- mounted() {
129
- if (window.wkl_product) {
130
- this.$emit('update', window.wkl_product)
131
- }
132
- this.$bus.$on('changePhoto', (photoId) => {
133
- let imageIndex = _.findIndex(this.product?.images, { id: photoId })
134
- if (imageIndex >= 0) {
135
- this.activeImage = imageIndex
136
- }
137
- })
97
+ const getSrcset = (imgdata) => {
98
+ if (!imgdata.available_sizes) return
99
+ let srcset = []
100
+ imgdata.available_sizes.forEach(asize => {
101
+ srcset.push(`${asize.url} ${asize.width}w`)
102
+ })
103
+ return srcset.join(', ')
104
+ }
105
+
106
+ const switchGallery = (value) => {
107
+ if (mq.value === 'mobile') {
108
+ gallery.value = false
109
+ return
110
+ }
111
+ gallery.value = value
112
+ if (value) {
113
+ document.documentElement.classList.add('is-clipped')
114
+ } else {
115
+ document.documentElement.classList.remove('is-clipped')
116
+ }
117
+ }
118
+
119
+ const handleChangePhoto = (photoId) => {
120
+ let imageIndex = props.product?.images?.findIndex(img => img.id === photoId)
121
+ if (imageIndex >= 0) {
122
+ activeImage.value = imageIndex
138
123
  }
139
124
  }
125
+
126
+ // Lifecycle hooks
127
+ onMounted(() => {
128
+ if (window.wkl_product) {
129
+ emit('update', window.wkl_product)
130
+ }
131
+ eventBus.on('changePhoto', handleChangePhoto)
132
+ })
133
+
134
+ onBeforeUnmount(() => {
135
+ eventBus.off('changePhoto', handleChangePhoto)
136
+ })
140
137
  </script>