actions.js
5 days ago
booking.js
5 days ago
cabinet.js
5 days ago
cart.js
5 days ago
catalog.js
5 days ago
coupon.js
5 days ago
customFields.js
5 days ago
events.js
5 days ago
facebookPixel.js
5 days ago
ivy.js
5 days ago
package.js
5 days ago
panel.js
5 days ago
public.js
5 days ago
renderActions.js
5 days ago
restore.js
5 days ago
slots.js
5 days ago
translation.js
5 days ago
user.js
5 days ago
cart.js
186 lines
| 1 | import { settings } from '../../../plugins/settings' |
| 2 | |
| 3 | function useCart(store) { |
| 4 | return store.getters['booking/getAllMultipleAppointments'] |
| 5 | } |
| 6 | |
| 7 | function useCartItem(store) { |
| 8 | return store.getters['booking/getAllMultipleAppointments'][ |
| 9 | store.getters['booking/getCartItemIndex'] |
| 10 | ] |
| 11 | } |
| 12 | |
| 13 | function useCartHasItems(store) { |
| 14 | let cart = useCart(store) |
| 15 | |
| 16 | let hasItems = 0 |
| 17 | |
| 18 | cart.forEach((item) => { |
| 19 | if (!item.packageId) { |
| 20 | Object.keys(item.services).forEach((serviceId) => { |
| 21 | if (item.services[serviceId].list.filter((i) => i.date && i.time && i.providerId).length) { |
| 22 | hasItems++ |
| 23 | } |
| 24 | }) |
| 25 | } |
| 26 | }) |
| 27 | |
| 28 | return hasItems |
| 29 | } |
| 30 | |
| 31 | function useCartStep(store) { |
| 32 | let preselected = store.getters['entities/getPreselected'] |
| 33 | |
| 34 | return ( |
| 35 | settings.payments.cart && |
| 36 | !( |
| 37 | preselected.show === 'packages' || |
| 38 | (Array.isArray(preselected.package) ? preselected.package.length : preselected.package) |
| 39 | ) |
| 40 | ) |
| 41 | } |
| 42 | |
| 43 | function useAddToCart(store) { |
| 44 | let index = store.getters['booking/getCartItemIndex'] |
| 45 | |
| 46 | let items = store.getters['booking/getAllMultipleAppointments'] |
| 47 | |
| 48 | index++ |
| 49 | |
| 50 | items[index] = { |
| 51 | packageId: null, |
| 52 | serviceId: null, |
| 53 | index: 0, |
| 54 | services: {}, |
| 55 | } |
| 56 | |
| 57 | store.commit('booking/setCartItemIndex', index) |
| 58 | } |
| 59 | |
| 60 | function useGoToCartStep(stepsArray, stepIndex) { |
| 61 | stepIndex.value = stepsArray.value.findIndex((i) => i.name === 'CartStep') |
| 62 | } |
| 63 | |
| 64 | function useInitSelection(store, deselectService) { |
| 65 | let preselected = store.getters['entities/getPreselected'] |
| 66 | |
| 67 | if (deselectService && !preselected.service.length) { |
| 68 | store.commit('booking/setServiceId', null) |
| 69 | store.commit('booking/setCategoryId', null) |
| 70 | } |
| 71 | |
| 72 | if (!preselected.employee.length) { |
| 73 | store.commit('booking/setEmployeeId', null) |
| 74 | } |
| 75 | |
| 76 | if (!preselected.location.length) { |
| 77 | store.commit('booking/setLocationId', null) |
| 78 | } |
| 79 | |
| 80 | if (!preselected.package.length) { |
| 81 | store.commit('booking/setPackageId', null) |
| 82 | |
| 83 | store.commit('booking/setBookableType', 'appointment') |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | function useResetCart(store) { |
| 88 | let items = store.getters['booking/getAllMultipleAppointments'] |
| 89 | |
| 90 | if (items[0].packageId) { |
| 91 | store.commit('booking/setMultipleAppointments', [ |
| 92 | { |
| 93 | packageId: null, |
| 94 | serviceId: null, |
| 95 | index: 0, |
| 96 | services: {}, |
| 97 | }, |
| 98 | ]) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | function useInitCartItem(store) { |
| 103 | let index = store.getters['booking/getCartItemIndex'] |
| 104 | |
| 105 | let items = store.getters['booking/getAllMultipleAppointments'] |
| 106 | |
| 107 | let serviceId = store.getters['booking/getServiceId'] |
| 108 | |
| 109 | let appointmentInstantiated = index in items && serviceId in items[index].services |
| 110 | |
| 111 | if ( |
| 112 | serviceId && |
| 113 | items[index] && |
| 114 | 'services' in items[index] && |
| 115 | !(serviceId in items[index].services) |
| 116 | ) { |
| 117 | items[index].index = 0 |
| 118 | |
| 119 | items[index].packageId = null |
| 120 | |
| 121 | items[index].serviceId = serviceId |
| 122 | |
| 123 | items[index].services = {} |
| 124 | |
| 125 | items[index].services[serviceId] = { |
| 126 | fetched: false, |
| 127 | slots: [], |
| 128 | providerId: store.getters['booking/getEmployeeId'], |
| 129 | locationId: store.getters['booking/getLocationId'], |
| 130 | list: [ |
| 131 | { |
| 132 | providerId: store.getters['booking/getEmployeeId'], |
| 133 | locationId: store.getters['booking/getLocationId'], |
| 134 | date: appointmentInstantiated |
| 135 | ? store.getters['booking/getMultipleAppointmentsDate'] |
| 136 | : null, |
| 137 | time: appointmentInstantiated |
| 138 | ? store.getters['booking/getMultipleAppointmentsTime'] |
| 139 | : null, |
| 140 | range: appointmentInstantiated |
| 141 | ? store.getters['booking/getMultipleAppointmentsRange'] |
| 142 | : { start: null, end: null }, |
| 143 | persons: 1, |
| 144 | extras: [], |
| 145 | duration: null, |
| 146 | price: null, |
| 147 | }, |
| 148 | ], |
| 149 | } |
| 150 | } else if (!serviceId) { |
| 151 | items[index].index = '' |
| 152 | |
| 153 | items[index].services = {} |
| 154 | |
| 155 | items[index].packageId = null |
| 156 | |
| 157 | items[index].serviceId = null |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | function useRemoveLastCartItem(store) { |
| 162 | let items = store.getters['booking/getAllMultipleAppointments'] |
| 163 | |
| 164 | if ( |
| 165 | !items[items.length - 1].services[items[items.length - 1].serviceId].list[0].date && |
| 166 | !items[items.length - 1].services[items[items.length - 1].serviceId].list[0].time |
| 167 | ) { |
| 168 | items.pop() |
| 169 | |
| 170 | store.commit('booking/setCartItemIndex', items.length - 1) |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | export { |
| 175 | useInitSelection, |
| 176 | useAddToCart, |
| 177 | useGoToCartStep, |
| 178 | useCartHasItems, |
| 179 | useInitCartItem, |
| 180 | useCartStep, |
| 181 | useCart, |
| 182 | useResetCart, |
| 183 | useCartItem, |
| 184 | useRemoveLastCartItem, |
| 185 | } |
| 186 |