@viur/shop-components 0.9.3 → 0.9.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viur/shop-components",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "Frontend Vue components for the shop module of ViUR",
5
5
  "repository": {
6
6
  "type": "git",
package/src/Shop.vue CHANGED
@@ -61,100 +61,129 @@
61
61
 
62
62
 
63
63
  <script setup>
64
- import { onBeforeMount, watch, reactive } from 'vue';
65
- import ShopOrderStepper from './ShopOrderStepper.vue'
66
- import ShopSummary from "./ShopSummary.vue"
67
- import {useViurShopStore} from './shop'
68
- import { useUrlSearchParams } from '@vueuse/core'
69
- import { useOrder } from './composables/order';
70
- import { useCart } from './composables/cart';
71
- import {getTranslations} from './utils'
72
-
73
-
74
- const shopStore = useViurShopStore()
75
- const {fetchOrder} = useOrder()
76
- const {fetchCart} = useCart()
77
-
78
- const emit = defineEmits('change')
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
- summary:{
83
- default:false
84
- }, // bottom, sidebar
85
- initTab:{
86
- default:'cart'
87
- },
88
- modulename:{
89
- default:'shop'
90
- },
91
- debug:{
92
- default:false
93
- },
94
- showCartNodes:{
95
- default:false
96
- },
97
- topActions:{
98
- default:false
99
- },
100
- language:{
101
- default:"de"
102
- },
103
- locale: {
104
- default: 'de-DE',
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
- getTranslations([props.language], "viur.shop.*").then((resp)=>{
115
- state.translationsLoaded = true
116
- })
117
- shopStore.state.language = props.language
118
- shopStore.state.locale = props.locale
119
- shopStore.state.showNodes = props.showCartNodes
120
- shopStore.state.debug = props.debug
121
- shopStore.state.topActions = props.topActions
122
- if(props.tabs){
123
- shopStore.state.tabs = props.tabs
124
- }
125
-
126
- shopStore.state.moduleName= props.modulename
127
- shopStore.fetchMetaData()
128
- const params = useUrlSearchParams('hash')
129
- if (Object.keys(params).includes('order')){
130
- shopStore.state.orderKey = params['order']
131
- fetchOrder(shopStore.state.orderKey).then(()=>{
132
- fetchCart(); // load after cartKey has been loaded from order
133
- shopStore.state.orderReady = true
134
- // navigate to order state
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
- }else{
142
- fetchCart()
143
- shopStore.state.orderReady = true
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
- if (Object.keys(params).includes('step')){
148
- shopStore.navigateToTab(params['step'])
149
- }else{
150
- shopStore.navigateToTab('cart')
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>
@@ -82,7 +82,7 @@ const state = reactive({
82
82
  paymentHandler:{},
83
83
  loading:false,
84
84
  hasError:false,
85
- errorMessage:"Bei der Zahlung ist ein Fehler aufgetreten.",
85
+ errorMessage: null,
86
86
  waitPayment:false
87
87
  })
88
88
 
@@ -138,6 +138,7 @@ function paymentError(error){
138
138
  console.error(error)
139
139
  state.loading = false
140
140
  state.hasError = true
141
+ state.errorMessage = error.customerMessage || error.message || error || 'Error';
141
142
  }
142
143
 
143
144