@viur/shop-components 0.0.1-dev.10 → 0.0.1-dev.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viur/shop-components",
3
- "version": "0.0.1-dev.10",
3
+ "version": "0.0.1-dev.12",
4
4
  "description": "Frontend Vue components for the shop module of ViUR",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,11 @@
1
+ <template>
2
+ <div>test</div>
3
+ </template>
4
+
5
+ <script setup>
6
+
7
+ </script>
8
+
9
+ <style scoped>
10
+
11
+ </style>
@@ -1,6 +1,8 @@
1
1
  <template>
2
- <Loader v-if="!state.cartIsInit"></Loader>
3
- <pre v-else> {{ cartStore.state }}</pre>
2
+ <pre> {{ state.nodes }}</pre>
3
+ <pre> {{ state.leaves }}</pre>
4
+ <!-- <CartNode></CartNode>
5
+ <CartLeaf></CartLeaf> -->
4
6
  <!-- <template v-else>
5
7
  <div class="bind viur-shop-cart-wrap">
6
8
  <sl-dialog ref="confirm" @sl-hide="onDialogHide">
@@ -233,11 +235,12 @@
233
235
  import { reactive, computed, onBeforeMount, ref } from "vue";
234
236
  import Loader from "@viur/vue-utils/generic/Loader.vue";
235
237
  import { useCartStore } from "../../stores/cart.js";
236
- import { Request } from "@viur/vue-utils";
238
+ import CartNode from "./CartNode.vue";
239
+ import CartLeaf from "./CartLeaf.vue";
237
240
 
238
241
  const props = defineProps({
239
242
  mode: { type: String, default: "basket" },
240
- cartKey: { type: String, default: "" },
243
+ cartKey: { type: String, required: true },
241
244
  sidebar: { type: Boolean, default: true },
242
245
  });
243
246
 
@@ -254,6 +257,8 @@ const state = reactive({
254
257
  }),
255
258
  images: {},
256
259
  currentItem: {},
260
+ nodes: [],
261
+ leaves: {},
257
262
  });
258
263
 
259
264
  const currentCartKey = computed(() => {
@@ -308,8 +313,29 @@ function onDialogHide() {
308
313
  state.currentItem = {};
309
314
  }
310
315
 
316
+ async function getChildren(parentKey = props.key) {
317
+ const children = await cartStore.getChildren(parentKey);
318
+
319
+ children.forEach(async (child) => {
320
+ if (child.skel_type === "node") {
321
+ state.nodes.push(child);
322
+ await getChildren(child.key);
323
+ } else {
324
+ if (!Object.keys(state.leaves).includes(parentKey)) {
325
+ state.leaves[parentKey] = [];
326
+ }
327
+ state.leaves[parentKey].push(child);
328
+ }
329
+ });
330
+ }
331
+
311
332
  onBeforeMount(async () => {
312
333
  await cartStore.init();
334
+ await getChildren();
335
+
336
+ console.log("state.nodes", state.nodes);
337
+
338
+ console.log("state.leaves", state.leaves);
313
339
  });
314
340
  </script>
315
341
 
@@ -21,7 +21,11 @@ const state = reactive({
21
21
  tabs: {
22
22
  cart: {
23
23
  component: shallowRef(CartView),
24
- props: { sidebar: true, mode: "basket" },
24
+ props: {
25
+ sidebar: true,
26
+ mode: "basket",
27
+ cartKey: cartStore.state.basketRootNode.key,
28
+ }, // cartKey (on initial call has to be a root node) is a required prop, make sure that cartStore.init() is called before cart is mounted
25
29
  displayName: "Warenkorb",
26
30
  icon: { name: "cart", library: "hsk" },
27
31
  position: 2,
@@ -95,6 +99,7 @@ function handleTabs(e) {
95
99
  }
96
100
 
97
101
  onBeforeMount(async () => {
102
+ await cartStore.init();
98
103
  await cartStore.getAdressStructure();
99
104
  });
100
105
  </script>
@@ -33,9 +33,9 @@ export const useCartStore = defineStore("cartstore", () => {
33
33
  await getChildren(child.key);
34
34
  } else {
35
35
  if (!Object.keys(state.children).includes(child.key)) {
36
- children[parentKey] = [];
36
+ state.children[parentKey] = [];
37
37
  }
38
- children[parentKey].push(child);
38
+ state.children[parentKey].push(child);
39
39
  }
40
40
  });
41
41
  }
@@ -48,7 +48,7 @@ export const useCartStore = defineStore("cartstore", () => {
48
48
  if (rootNode.cart_type === "basket") {
49
49
  state.basketRootNode = rootNode;
50
50
  } else {
51
- whishlistRootNodes.push(rootNode);
51
+ state.whishlistRootNodes.push(rootNode);
52
52
  }
53
53
  }
54
54
  });