@viur/shop-components 0.9.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viur/shop-components",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
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,96 +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
- })
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
+ });
104
110
 
105
111
  const state = reactive({
106
- translationsLoaded:false
107
- })
108
-
109
-
110
- onBeforeMount(()=>{
111
- getTranslations([props.language], "viur.shop.*").then((resp)=>{
112
- state.translationsLoaded = true
113
- })
114
- shopStore.state.language = props.language
115
- shopStore.state.showNodes = props.showCartNodes
116
- shopStore.state.debug = props.debug
117
- shopStore.state.topActions = props.topActions
118
- if(props.tabs){
119
- shopStore.state.tabs = props.tabs
120
- }
121
-
122
- shopStore.state.moduleName= props.modulename
123
- shopStore.fetchMetaData()
124
- const params = useUrlSearchParams('hash')
125
- if (Object.keys(params).includes('order')){
126
- shopStore.state.orderKey = params['order']
127
- fetchOrder(shopStore.state.orderKey).then(()=>{
128
- fetchCart(); // load after cartKey has been loaded from order
129
- shopStore.state.orderReady = true
130
- // navigate to order state
131
- if(shopStore.state.order?.['is_ordered']){
132
- shopStore.navigateToTab('complete')
133
- } else if (shopStore.state.order?.['is_checkout_in_progress']){
134
- 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];
135
138
  }
136
- })
137
- }else{
138
- fetchCart()
139
- shopStore.state.orderReady = true
140
- }
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
+ }
141
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
+ }
142
174
 
143
- if (Object.keys(params).includes('step')){
144
- shopStore.navigateToTab(params['step'])
145
- }else{
146
- shopStore.navigateToTab('cart')
147
- }
148
- })
175
+
176
+ if (Object.keys(params).includes('step')) {
177
+ shopStore.navigateToTab(params['step']);
178
+ } else {
179
+ shopStore.navigateToTab('cart');
180
+ }
181
+ });
149
182
 
150
183
 
151
- watch(()=>shopStore.state.currentTab, (newVal,oldVal)=>{
152
- emit('change', newVal)
153
- })
184
+ watch(() => shopStore.state.currentTab, (newVal, oldVal) => {
185
+ emit('change', newVal);
186
+ });
154
187
 
155
188
 
156
189
  </script>
@@ -181,9 +214,10 @@ watch(()=>shopStore.state.currentTab, (newVal,oldVal)=>{
181
214
  }
182
215
 
183
216
  @layer foundation.shop {
184
- :root{
185
- --viur-shop-sidebar-height-offset:0;
217
+ :root {
218
+ --viur-shop-sidebar-height-offset: 0;
186
219
  }
220
+
187
221
  .viur-shop-sidebar-wrap {
188
222
  --padding: var(--sl-spacing-large);
189
223
 
@@ -197,9 +231,11 @@ watch(()=>shopStore.state.currentTab, (newVal,oldVal)=>{
197
231
  height: min-content;
198
232
  grid-column: auto / span 12;
199
233
  order: -1;
234
+
200
235
  & > * + * {
201
236
  margin-top: var(--sl-spacing-small);
202
237
  }
238
+
203
239
  @media (min-width: 1024px) {
204
240
  position: sticky;
205
241
  max-height: calc(100vh - var(--viur-shop-sidebar-height-offset) - 2 * var(--padding));
@@ -258,5 +294,4 @@ watch(()=>shopStore.state.currentTab, (newVal,oldVal)=>{
258
294
  }
259
295
 
260
296
 
261
-
262
297
  </style>
@@ -77,7 +77,7 @@ const { pause:PaymentCheckPause, resume:PaymentCheckResume, isActive:PaymentChec
77
77
  const state = reactive({
78
78
  unzer:computed(()=>{
79
79
  if (!shopStore.state.paymentProviderData) return null
80
- return new unzer(shopStore.state.paymentProviderData["public_key"], {locale: 'de-DE'})
80
+ return new unzer(shopStore.state.paymentProviderData["public_key"], {locale: shopStore.state.locale})
81
81
  }),
82
82
  paymentHandler:{},
83
83
  loading:false,