@viur/shop-components 0.9.3 → 0.9.4
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/package.json +1 -1
- package/src/Shop.vue +118 -87
package/package.json
CHANGED
package/src/Shop.vue
CHANGED
|
@@ -61,100 +61,129 @@
|
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
<script setup>
|
|
64
|
-
import {
|
|
65
|
-
import
|
|
66
|
-
import
|
|
67
|
-
import {
|
|
68
|
-
import {
|
|
69
|
-
import {
|
|
70
|
-
import {
|
|
71
|
-
import
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const
|
|
64
|
+
import {useTranslations} from '@viur/vue-utils/utils/translations.js';
|
|
65
|
+
import {useUrlSearchParams} from '@vueuse/core';
|
|
66
|
+
import {onBeforeMount, reactive, watch} from 'vue';
|
|
67
|
+
import {useI18n} from 'vue-i18n';
|
|
68
|
+
import {useCart} from './composables/cart';
|
|
69
|
+
import {useOrder} from './composables/order';
|
|
70
|
+
import {useViurShopStore} from './shop';
|
|
71
|
+
import ShopOrderStepper from './ShopOrderStepper.vue';
|
|
72
|
+
import ShopSummary from './ShopSummary.vue';
|
|
73
|
+
import {getTranslations} from './utils';
|
|
74
|
+
|
|
75
|
+
const {fetchTranslations, updateLocaleMessages} = useTranslations();
|
|
76
|
+
const i18n = useI18n();
|
|
77
|
+
const shopStore = useViurShopStore();
|
|
78
|
+
const {fetchOrder} = useOrder();
|
|
79
|
+
const {fetchCart} = useCart();
|
|
80
|
+
|
|
81
|
+
const emit = defineEmits('change');
|
|
79
82
|
|
|
80
83
|
|
|
81
84
|
const props = defineProps({
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
})
|
|
85
|
+
summary: {
|
|
86
|
+
default: false,
|
|
87
|
+
}, // bottom, sidebar
|
|
88
|
+
initTab: {
|
|
89
|
+
default: 'cart',
|
|
90
|
+
},
|
|
91
|
+
modulename: {
|
|
92
|
+
default: 'shop',
|
|
93
|
+
},
|
|
94
|
+
debug: {
|
|
95
|
+
default: false,
|
|
96
|
+
},
|
|
97
|
+
showCartNodes: {
|
|
98
|
+
default: false,
|
|
99
|
+
},
|
|
100
|
+
topActions: {
|
|
101
|
+
default: false,
|
|
102
|
+
},
|
|
103
|
+
language: {
|
|
104
|
+
default: 'de',
|
|
105
|
+
},
|
|
106
|
+
locale: {
|
|
107
|
+
default: 'de-DE',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
107
110
|
|
|
108
111
|
const state = reactive({
|
|
109
|
-
translationsLoaded:false
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
onBeforeMount(()=>{
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if(shopStore.state.order?.['is_ordered']){
|
|
136
|
-
shopStore.navigateToTab('complete')
|
|
137
|
-
} else if (shopStore.state.order?.['is_checkout_in_progress']){
|
|
138
|
-
shopStore.navigateToTab('confirm')
|
|
112
|
+
translationsLoaded: false,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
onBeforeMount(() => {
|
|
117
|
+
getTranslations([props.language], 'viur.shop.*').then((resp) => {
|
|
118
|
+
// convert 'dot.seperated.translation.keys' to a {nested: {translation: 'object'} to overwrite the default object.
|
|
119
|
+
const nested = {};
|
|
120
|
+
Object.entries(resp).forEach(([lang, translations]) => {
|
|
121
|
+
nested[lang] = {};
|
|
122
|
+
Object.entries(translations).forEach(([key, value]) => {
|
|
123
|
+
const path = key.split('.');
|
|
124
|
+
let segment;
|
|
125
|
+
let current = nested[lang];
|
|
126
|
+
while (segment = path.shift()) {
|
|
127
|
+
if (path.length === 0) {
|
|
128
|
+
if (typeof current === 'string' || current instanceof String) {
|
|
129
|
+
console.warn(`The prefix of ${key} (before .${segment}) is another translation key and can't be nested`);
|
|
130
|
+
} else {
|
|
131
|
+
current[segment] = value;
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
if (!(segment in current)) {
|
|
135
|
+
current[segment] = {};
|
|
136
|
+
}
|
|
137
|
+
current = current[segment];
|
|
139
138
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
i18n.mergeLocaleMessage(lang, nested[lang]);
|
|
142
|
+
});
|
|
143
|
+
// console.debug(nested);
|
|
144
|
+
state.translationsLoaded = true;
|
|
145
|
+
});
|
|
146
|
+
shopStore.state.language = props.language;
|
|
147
|
+
shopStore.state.locale = props.locale;
|
|
148
|
+
shopStore.state.showNodes = props.showCartNodes;
|
|
149
|
+
shopStore.state.debug = props.debug;
|
|
150
|
+
shopStore.state.topActions = props.topActions;
|
|
151
|
+
if (props.tabs) {
|
|
152
|
+
shopStore.state.tabs = props.tabs;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
shopStore.state.moduleName = props.modulename;
|
|
156
|
+
shopStore.fetchMetaData();
|
|
157
|
+
const params = useUrlSearchParams('hash');
|
|
158
|
+
if (Object.keys(params).includes('order')) {
|
|
159
|
+
shopStore.state.orderKey = params['order'];
|
|
160
|
+
fetchOrder(shopStore.state.orderKey).then(() => {
|
|
161
|
+
fetchCart(); // load after cartKey has been loaded from order
|
|
162
|
+
shopStore.state.orderReady = true;
|
|
163
|
+
// navigate to order state
|
|
164
|
+
if (shopStore.state.order?.['is_ordered']) {
|
|
165
|
+
shopStore.navigateToTab('complete');
|
|
166
|
+
} else if (shopStore.state.order?.['is_checkout_in_progress']) {
|
|
167
|
+
shopStore.navigateToTab('confirm');
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
} else {
|
|
171
|
+
fetchCart();
|
|
172
|
+
shopStore.state.orderReady = true;
|
|
173
|
+
}
|
|
145
174
|
|
|
146
175
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
})
|
|
176
|
+
if (Object.keys(params).includes('step')) {
|
|
177
|
+
shopStore.navigateToTab(params['step']);
|
|
178
|
+
} else {
|
|
179
|
+
shopStore.navigateToTab('cart');
|
|
180
|
+
}
|
|
181
|
+
});
|
|
153
182
|
|
|
154
183
|
|
|
155
|
-
watch(()=>shopStore.state.currentTab, (newVal,oldVal)=>{
|
|
156
|
-
emit('change', newVal)
|
|
157
|
-
})
|
|
184
|
+
watch(() => shopStore.state.currentTab, (newVal, oldVal) => {
|
|
185
|
+
emit('change', newVal);
|
|
186
|
+
});
|
|
158
187
|
|
|
159
188
|
|
|
160
189
|
</script>
|
|
@@ -185,9 +214,10 @@ watch(()=>shopStore.state.currentTab, (newVal,oldVal)=>{
|
|
|
185
214
|
}
|
|
186
215
|
|
|
187
216
|
@layer foundation.shop {
|
|
188
|
-
:root{
|
|
189
|
-
--viur-shop-sidebar-height-offset:0;
|
|
217
|
+
:root {
|
|
218
|
+
--viur-shop-sidebar-height-offset: 0;
|
|
190
219
|
}
|
|
220
|
+
|
|
191
221
|
.viur-shop-sidebar-wrap {
|
|
192
222
|
--padding: var(--sl-spacing-large);
|
|
193
223
|
|
|
@@ -201,9 +231,11 @@ watch(()=>shopStore.state.currentTab, (newVal,oldVal)=>{
|
|
|
201
231
|
height: min-content;
|
|
202
232
|
grid-column: auto / span 12;
|
|
203
233
|
order: -1;
|
|
234
|
+
|
|
204
235
|
& > * + * {
|
|
205
236
|
margin-top: var(--sl-spacing-small);
|
|
206
237
|
}
|
|
238
|
+
|
|
207
239
|
@media (min-width: 1024px) {
|
|
208
240
|
position: sticky;
|
|
209
241
|
max-height: calc(100vh - var(--viur-shop-sidebar-height-offset) - 2 * var(--padding));
|
|
@@ -262,5 +294,4 @@ watch(()=>shopStore.state.currentTab, (newVal,oldVal)=>{
|
|
|
262
294
|
}
|
|
263
295
|
|
|
264
296
|
|
|
265
|
-
|
|
266
297
|
</style>
|