@viur/shop-components 0.0.1-dev.3 → 0.0.1-dev.31

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.
@@ -0,0 +1,112 @@
1
+ import { reactive } from "vue";
2
+ import { Request, ListRequest } from "@viur/vue-utils";
3
+ import { defineStore } from "pinia";
4
+ import { ViURShopClient } from "@viur/viur-shop-client";
5
+
6
+ export const useCartStore = defineStore("cartstore", () => {
7
+ const shopClient = new ViURShopClient({
8
+ host_url:
9
+ window.location.origin === "http://localhost:8081"
10
+ ? "http://localhost:8080"
11
+ : window.location.origin,
12
+ });
13
+
14
+ const state = reactive({
15
+ basketRootNode: {},
16
+ whishlistRootNodes: [],
17
+ children: {},
18
+ structure: { address: {}, cart: {} },
19
+ });
20
+
21
+ async function init() {
22
+ await getRootNodes();
23
+ }
24
+
25
+ async function getChildren(parentKey) {
26
+ let resp = await shopClient.cart_list({ cart_key: parentKey });
27
+
28
+ return resp
29
+ }
30
+
31
+ async function getRootNodes() {
32
+ let resp = await shopClient.cart_list();
33
+
34
+ resp.forEach((rootNode) => {
35
+ if (rootNode.is_root_node) {
36
+ if (rootNode.cart_type === "basket") {
37
+ state.basketRootNode = rootNode;
38
+ } else {
39
+ state.whishlistRootNodes.push(rootNode);
40
+ }
41
+ }
42
+ });
43
+ }
44
+
45
+ async function addToCart(articleKey, cartKey) {
46
+ let resp = await shopClient.article_add({
47
+ article_key: articleKey,
48
+ parent_cart_key: cartKey,
49
+ });
50
+
51
+ // await updateCart(cartKey);
52
+ console.log("addToCart", resp); //TODO: Errorhandling as soon as shop module works again
53
+ }
54
+
55
+ async function getArticleView(articleKey, cartKey) {
56
+ let article = await shopClient.article_view({
57
+ article_key: articleKey,
58
+ parent_cart_key: cartKey,
59
+ });
60
+
61
+ console.log("getArticleView", article); // ? Talk about necessarity
62
+ }
63
+
64
+ async function removeItem(articleKey, cartKey) {
65
+ let resp = await shopClient.article_remove({
66
+ article_key: articleKey,
67
+ parent_cart_key: cartKey,
68
+ });
69
+
70
+ console.log("remove Resp", resp); //TODO: Errorhandling as soon as shop module works again
71
+ }
72
+
73
+ async function updateItem(articleKey, cartKey, quantity) {
74
+ let resp = await shopClient.article_update({
75
+ article_key: articleKey,
76
+ parent_cart_key: cartKey,
77
+ quantity: quantity,
78
+ quantity_mode: "replace",
79
+ });
80
+
81
+ console.log("update Resp", resp); //TODO: Errorhandling as soon as shop module works again
82
+ }
83
+
84
+ // async function updateCart(cartKey) {
85
+ // await getChildren(cartKey);
86
+ // }
87
+
88
+ async function getAdressStructure() {
89
+ let addSkel = await shopClient.address_structure();
90
+ state.structure.address = addSkel.addSkel;
91
+
92
+ console.log("adress add", state.structure.address);
93
+
94
+ // Request.getStructure("shop.address").then(async (resp) => {
95
+ // let data = await resp.json();
96
+ // state.structure.address = data.addSkel;
97
+
98
+ // console.log("adress add", state.structure.address);
99
+ // });
100
+ }
101
+
102
+ return {
103
+ state,
104
+ addToCart,
105
+ getArticleView,
106
+ removeItem,
107
+ updateItem,
108
+ init,
109
+ getAdressStructure,
110
+ getChildren,
111
+ };
112
+ });
@@ -0,0 +1,20 @@
1
+ <template>
2
+ <div class="home">View {{ route.path }} is missing.</div>
3
+ </template>
4
+
5
+ <script>
6
+ import { defineComponent, reactive } from "vue"
7
+ import { useRoute } from "vue-router"
8
+
9
+ export default defineComponent({
10
+ props: {},
11
+ components: {},
12
+ setup(props, context) {
13
+ const route = useRoute()
14
+ const state = reactive({})
15
+ return { state, route }
16
+ }
17
+ })
18
+ </script>
19
+
20
+ <style scoped></style>