@viur/shop-components 0.1.10 → 0.1.12

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/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  <div align="center">
2
- <h1>ViUR Shop Components (WIP)</h1>
2
+ <img src="https://github.com/viur-framework/viur-artwork/raw/main/icons/icon-shop-components.svg" height="196" alt="A hexagonal logo of Shop Components" title="Shop Components logo"/>
3
+ <h1>ViUR Shop Components</h1>
3
4
  <a href="https://www.npmjs.com/package/@viur/shop-components">
4
5
  <img alt="Badge showing current NPM version" title="PyPI" src="https://img.shields.io/npm/v/@viur/shop-components">
5
6
  </a>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viur/shop-components",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Frontend Vue components for the shop module of ViUR",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,23 +23,20 @@
23
23
  "watch": "vite build --watch"
24
24
  },
25
25
  "dependencies": {
26
- "@tanstack/vue-table": "^8.20.5",
27
26
  "@viur/ignite": "^5.1.2",
28
- "@viur/shoelace": "^1.0.8-v2.19.0",
29
- "@viur/vue-utils": "^1.8.2",
30
- "@vueuse/core": "^11.1.0",
31
- "pinia": "^2.2.4",
32
- "primevue": "^4.1.1",
33
- "vue": "^3.5.12",
34
- "vue-i18n": "^10.0.4",
35
- "vue-router": "^4.4.5"
27
+ "@viur/shoelace": "^1.0.10-v2.20.0",
28
+ "@viur/vue-utils": "^2.2.5",
29
+ "@vueuse/core": "^13.0.0",
30
+ "pinia": "^3.0.1",
31
+ "vue": "^3.5.13",
32
+ "vue-i18n": "^11.1.2",
33
+ "vue-router": "^4.5.0"
36
34
  },
37
35
  "devDependencies": {
38
- "@faker-js/faker": "^9.0.3",
39
- "@vitejs/plugin-vue": "^5.1.4",
40
- "postcss-custom-media": "^11.0.3",
41
- "postcss-nesting": "^13.0.0",
42
- "prettier": "^3.3.3",
43
- "vite": "^5.4.9"
36
+ "@vitejs/plugin-vue": "^5.2.3",
37
+ "postcss-custom-media": "^11.0.5",
38
+ "postcss-nesting": "^13.0.1",
39
+ "prettier": "^3.5.3",
40
+ "vite": "^6.2.3"
44
41
  }
45
42
  }
package/src/Shop.vue CHANGED
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="bind viur-shop-wrap" v-bind="$attrs" v-if="shopStore.state.cartReady && shopStore.state.orderReady">
2
+ <div class="bind viur-shop-wrap" v-bind="$attrs" v-if="shopStore.state.cartReady && shopStore.state.orderReady && state.translationsLoaded">
3
3
  <div class="viur-shop-stepper-wrap"
4
4
  :class="{ 'full-width': (!summary || summary==='bottom' || shopStore.state.currentTab==='complete') }"
5
5
  >
@@ -61,13 +61,14 @@
61
61
 
62
62
 
63
63
  <script setup>
64
- import { onBeforeMount, watch } from 'vue';
64
+ import { onBeforeMount, watch, reactive } from 'vue';
65
65
  import ShopOrderStepper from './ShopOrderStepper.vue'
66
66
  import ShopSummary from "./ShopSummary.vue"
67
67
  import {useViurShopStore} from './shop'
68
68
  import { useUrlSearchParams } from '@vueuse/core'
69
69
  import { useOrder } from './composables/order';
70
70
  import { useCart } from './composables/cart';
71
+ import {getTranslations} from './utils'
71
72
 
72
73
 
73
74
  const shopStore = useViurShopStore()
@@ -87,13 +88,30 @@ const props = defineProps({
87
88
  modulename:{
88
89
  default:'shop'
89
90
  },
90
- debug:false,
91
- showCartNodes:false,
92
- topActions:false
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
+ })
104
+
105
+ const state = reactive({
106
+ translationsLoaded:false
93
107
  })
94
108
 
95
109
 
96
110
  onBeforeMount(()=>{
111
+ getTranslations([props.language], "viur.shop.*").then((resp)=>{
112
+ state.translationsLoaded = true
113
+ })
114
+ shopStore.state.language = props.language
97
115
  shopStore.state.showNodes = props.showCartNodes
98
116
  shopStore.state.debug = props.debug
99
117
  shopStore.state.topActions = props.topActions
@@ -27,6 +27,11 @@
27
27
  label="placeholder">
28
28
  </slot>
29
29
 
30
+ <slot boneName="address_addition"
31
+ :widget="getBoneWidget(formState.structure['address_addition']['type'])"
32
+ label="placeholder">
33
+ </slot>
34
+
30
35
  <slot
31
36
  boneName="zip_code"
32
37
  :widget="getBoneWidget(formState.structure['zip_code']['type'])"
@@ -94,6 +99,10 @@ const formUpdate = inject("formUpdate");
94
99
  grid-column: 4 / span 1;
95
100
  }
96
101
 
102
+ :deep(.wrapper-bone-address_addition){
103
+ grid-column: 1 / span 4;
104
+ }
105
+
97
106
  :deep(.wrapper-bone-zip_code){
98
107
  grid-column: 1 / span 2;
99
108
  }
@@ -15,7 +15,10 @@
15
15
  <h5 v-if="item.shop_art_no_or_gtin" class="viur-shop-cart-leaf-artno" slot="header">
16
16
  {{ getValue(item.shop_art_no_or_gtin) }}
17
17
  </h5>
18
- <a class="viur-shop-cart-leaf-headline-link" :href="item.article.dest.view_url" v-if="item.article?.dest?.view_url">
18
+ <a class="viur-shop-cart-leaf-headline-link"
19
+ v-if="item.article?.dest?.shop_view_url ?? item.article?.dest?.view_url"
20
+ :href="item.article?.dest?.shop_view_url ?? item.article?.dest?.view_url"
21
+ >
19
22
  <h4
20
23
  class="viur-shop-cart-leaf-headline headline"
21
24
  v-html="getValue(item.shop_name)"
@@ -52,10 +55,10 @@
52
55
  </sl-bar>
53
56
  </template>
54
57
  </dialog-Button>
55
- <sl-button slot="prefix" v-else @click="changeAmount(item.quantity-=1)">
58
+ <sl-button slot="prefix" v-else :disabled="!edit" @click="changeAmount(item.quantity-=1)">
56
59
  <sl-icon name="dash-lg"></sl-icon>
57
60
  </sl-button>
58
- <sl-button slot="suffix" @click="changeAmount(item.quantity+=1)">
61
+ <sl-button slot="suffix" :disabled="!edit" @click="changeAmount(item.quantity+=1)">
59
62
  <sl-icon name="plus-lg"></sl-icon>
60
63
  </sl-button>
61
64
  </sl-input>
@@ -37,10 +37,10 @@
37
37
  </sl-bar>
38
38
  </template>
39
39
  </dialog-Button>
40
- <sl-button slot="prefix" v-else @click="changeAmount(item.quantity-=1)">
40
+ <sl-button slot="prefix" v-else :disabled="!edit" @click="changeAmount(item.quantity-=1)">
41
41
  <sl-icon name="dash-lg"></sl-icon>
42
42
  </sl-button>
43
- <sl-button slot="suffix" @click="changeAmount(item.quantity+=1)">
43
+ <sl-button slot="suffix" :disabled="!edit" @click="changeAmount(item.quantity+=1)">
44
44
  <sl-icon name="plus-lg"></sl-icon>
45
45
  </sl-button>
46
46
  </sl-input>
package/src/main.js CHANGED
@@ -1,8 +1,9 @@
1
1
  // imports
2
2
  import { createPinia } from "pinia";
3
3
  import { createI18n } from "vue-i18n";
4
- import { getTranslations } from "./utils";
5
4
  import { de_translations, en_translations } from "@viur/vue-utils";
5
+ import {useTranslations} from "@viur/vue-utils/utils/translations"
6
+
6
7
  import en from "./translations/en"
7
8
  import de from "./translations/de"
8
9
  import fr from "./translations/fr"
@@ -11,7 +12,10 @@ export { default as ViurShop } from "./Shop.vue";
11
12
 
12
13
  const ViurShopComponents = {
13
14
  async install(app,options) {
15
+
16
+
14
17
 
18
+
15
19
  let defaultLocale = options?.defaultLocale?options.defaultLocale:'de'
16
20
  let locale = options?.locale?options.locale:['de']
17
21
  let fallback = options?.fallback?options.fallback:'en'
@@ -21,12 +25,17 @@ const ViurShopComponents = {
21
25
  app.use(createPinia());
22
26
 
23
27
  let messages = {}
28
+ const i18n = createI18n({
29
+ locale: defaultLocale,
30
+ fallbackLocale: fallback,
31
+ messages: messages,
32
+ })
33
+ const {fetchTranslations, updateLocaleMessages} = useTranslations(i18n.global)
24
34
  // fetch translations from server
25
- let data = await getTranslations(locale,options?.pattern)
35
+ let data = await fetchTranslations(locale,options?.pattern)
26
36
  for(const loc of locale){
27
37
  let locAdditionals = additionals?.[loc]?additionals[loc]:{}
28
38
 
29
-
30
39
  if (loc === 'de'){
31
40
  messages[loc] = { ...de_translations, ...de, ...locAdditionals, ...data[loc]}
32
41
  }else if (loc === 'fr'){
@@ -36,15 +45,10 @@ const ViurShopComponents = {
36
45
  }else{
37
46
  messages[loc] = {...locAdditionals, ...data[loc]}
38
47
  }
48
+ updateLocaleMessages(loc, messages[loc])
39
49
  }
40
-
41
- // server_translations will be overwritten by utils. Both are overwritten by local shop translations
42
50
  app.use(
43
- createI18n({
44
- locale: defaultLocale,
45
- fallbackLocale: fallback,
46
- messages: messages,
47
- })
51
+ i18n
48
52
  );
49
53
  },
50
54
  };
@@ -60,5 +60,7 @@ export default {
60
60
  wait_for_payment:"Warte auf Zahlung...",
61
61
  remove_article_from_cart:"Wollen sie den Artikel wirklich entfernen?",
62
62
  order_check_later:"Sie können Ihre Bestellung am Ende noch einmal überprüfen.",
63
- }
63
+ },
64
+ "skeleton.address.address_type.billing":"Rechnungsadresse",
65
+ "skeleton.address.address_type.shipping":"Lieferadresse",
64
66
  }
package/src/utils.js CHANGED
@@ -1,4 +1,9 @@
1
1
  import {Request} from '@viur/vue-utils'
2
+ import {useTranslations} from "@viur/vue-utils/utils/translations"
3
+ import { de_translations, en_translations } from "@viur/vue-utils";
4
+ import en from "./translations/en"
5
+ import de from "./translations/de"
6
+ import fr from "./translations/fr"
2
7
 
3
8
  export function uuid() {
4
9
  return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) =>
@@ -20,29 +25,25 @@ export function struct2dict(structure) {
20
25
  return result;
21
26
  }
22
27
 
23
- export async function getTranslations(languages=["de"],pattern=null){
24
- // fetch translations from server
25
- let retVal = languages.reduce((acc,item)=>{acc[item]={}; return acc;},{})
26
- try {
27
- let dataObj = {languages:languages}
28
- if(pattern){
29
- dataObj['pattern'] = pattern
30
- }
28
+ export function getTranslations(languages="de", pattern=null){
29
+ if (!Array.isArray(languages)){
30
+ languages = [languages]
31
+ }
32
+
33
+ const {fetchTranslations, updateLocaleMessages} = useTranslations()
34
+ let default_messages={
35
+ "de":{ ...de_translations, ...de },
36
+ "en":{ ...en_translations, ...en },
37
+ "fr":{ ...fr },
38
+
39
+ }
31
40
 
32
- let translations = await Request.get("/json/_translation/get_public",{dataObj:dataObj})
33
- const data = await translations.json()
34
- for (let country in data) {
35
- data[country] = Object.fromEntries(
36
- Object.entries(data[country]).map(
37
- ([key, value], idx) => [key, value.replaceAll('{{', '{').replaceAll('}}', '}').replace(/([@$|])/g, '{\'$1\'}')],
38
- ),
39
- )
41
+ for(const loc of languages){
42
+ if (default_messages?.[loc]){
43
+ updateLocaleMessages(loc, default_messages[loc])
40
44
  }
41
- retVal = data
42
- }catch(error){
43
- console.log("No Translation from server", error)
44
45
  }
45
- return retVal
46
+ return fetchTranslations(languages,pattern)
46
47
  }
47
48
 
48
49
  export function getImage(image) {