@viur/shop-components 0.0.1-dev.2 → 0.0.1-dev.21

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,210 @@
1
+ <template>
2
+ <div class="bind viur-shop-wrap">
3
+ <sl-tab-group
4
+ class="viur-shop-order-tab"
5
+ noScrollControls
6
+ @sl-tab-show="onTabChange"
7
+ ref="tabGroup"
8
+ >
9
+ <sl-tab
10
+ slot="nav"
11
+ :panel="tab"
12
+ v-for="(tab, index) in state.tabNames"
13
+ :key="tab"
14
+ :disabled="tabs[tab].disabled"
15
+ >
16
+ <div class="viur-shop-order-step">
17
+ <sl-icon
18
+ :name="tabs[tab].icon.name"
19
+ :library="tabs[tab].icon.library"
20
+ >
21
+ </sl-icon>
22
+ <div class="viur-shop-order-status-text">
23
+ {{ index + 1 }}. {{ tabs[tab].displayName }}
24
+ </div>
25
+ </div>
26
+ <sl-icon
27
+ name="chevron-right"
28
+ class="viur-shop-order-tab-check"
29
+ v-if="index < state.tabNames.length - 1"
30
+ ></sl-icon>
31
+ </sl-tab>
32
+
33
+ <sl-tab-panel
34
+ :name="tab"
35
+ v-for="(tab, index) in state.tabNames"
36
+ :key="tab"
37
+ >
38
+ <component
39
+ :is="tabs[tab].component"
40
+ v-bind="tabs[tab].props ? tabs[tab].props : ''"
41
+ >
42
+ </component>
43
+ <div
44
+ class="viur-shop-form-footer"
45
+ :class="{ 'flex-end': state.isFirstTab(index) }"
46
+ v-if="index !== state.tabNames.length - 1"
47
+ >
48
+ <sl-button type="submit" v-show="index !== 0" @click="prevTab(state.tabNames[index-1])">
49
+ Zurück
50
+ </sl-button>
51
+ <!-- :disabled="!state.requiredFieldsFilled" -->
52
+ <sl-button type="submit" variant="primary" @click="nextTab(state.tabNames[index+1])">
53
+ Weiter
54
+ </sl-button>
55
+ </div>
56
+ </sl-tab-panel>
57
+ </sl-tab-group>
58
+
59
+ <div class="viur-shop-sidebar" id="order_sidebar"></div>
60
+ </div>
61
+ </template>
62
+
63
+ <script setup>
64
+ import { reactive, computed, ref } from "vue";
65
+
66
+ const props = defineProps({
67
+ tabs: {
68
+ type: Object,
69
+ required: true,
70
+ },
71
+ });
72
+
73
+ const emit = defineEmits(["tabChange"]);
74
+
75
+ const state = reactive({
76
+ tabNames: computed(() => sortTabs(props.tabs)),
77
+ isFirstTab: (index) => {
78
+ if (index === 0) {
79
+ return true;
80
+ }
81
+ return false;
82
+ },
83
+ });
84
+
85
+ const tabGroup = ref(null);
86
+
87
+ function sortTabs(tabs) {
88
+ let sortedArray = [];
89
+ let outputArray = [];
90
+
91
+ for (const tab in tabs) {
92
+ if (tabs[tab].position) {
93
+ sortedArray.push([tab, tabs[tab].position]);
94
+ } else {
95
+ sortedArray.push([tab, 0]);
96
+ }
97
+ }
98
+
99
+ sortedArray.sort((a, b) => {
100
+ return a[1] - b[1];
101
+ });
102
+
103
+ sortedArray.forEach((tab) => {
104
+ outputArray.push(tab[0]);
105
+ });
106
+
107
+ return outputArray;
108
+ }
109
+
110
+ function onTabChange(e) {
111
+ emit("tabChange", e);
112
+ }
113
+
114
+
115
+ function prevTab(tabName) {
116
+ tabGroup.value.show(tabName);
117
+ }
118
+
119
+ function nextTab(tabName) {
120
+ tabGroup.value.show(tabName);
121
+ }
122
+ </script>
123
+
124
+ <style scoped>
125
+ .viur-shop-wrap {
126
+ flex-direction: row;
127
+ gap: var(--sl-spacing-x-large);
128
+ align-items: flex-start;
129
+ }
130
+
131
+ .viur-shop-sidebar {
132
+ display: flex;
133
+ flex-direction: column;
134
+ background-color: var(--sl-color-neutral-100);
135
+ min-width: 300px;
136
+ padding: var(--sl-spacing-medium);
137
+ position: sticky;
138
+ top: 0;
139
+ }
140
+
141
+ .viur-shop-order-tab {
142
+ sl-tab {
143
+ width: 25%;
144
+
145
+ &::part(base) {
146
+ width: 100%;
147
+ height: 100%;
148
+ display: flex;
149
+ justify-content: center;
150
+ align-items: center;
151
+ position: relative;
152
+ color: var(--sl-color-neutral-400);
153
+ }
154
+
155
+ &[aria-selected="true"]::part(base) {
156
+ color: var(--ignt-color-primary) !important;
157
+ }
158
+ }
159
+ }
160
+
161
+ .viur-shop-order-step {
162
+ width: 100%;
163
+ height: 100%;
164
+ display: flex;
165
+ flex-direction: column;
166
+ justify-content: flex-start;
167
+ align-items: center;
168
+
169
+ @media (--ignt-mq-max-break-small) {
170
+ justify-content: center;
171
+ }
172
+
173
+ sl-icon {
174
+ font-size: 2.5em;
175
+ margin-bottom: 10px;
176
+
177
+ @media (--ignt-mq-max-break-small) {
178
+ display: none;
179
+ }
180
+ }
181
+ }
182
+
183
+ .viur-shop-order-tab-check {
184
+ position: absolute;
185
+ right: -0.5em;
186
+
187
+ @media (--ignt-mq-max-break-small) {
188
+ font-size: 0.7em;
189
+ right: -0.35em;
190
+ top: calc(50% - 0.35em);
191
+ }
192
+ }
193
+
194
+ .viur-shop-order-status-text {
195
+ font-size: 0.8em;
196
+ color: inherit;
197
+ text-align: center;
198
+ margin-top: 0.6em;
199
+ white-space: initial;
200
+ }
201
+
202
+ .viur-shop-form-footer {
203
+ display: flex;
204
+ justify-content: space-between;
205
+ margin-top: var(--sl-spacing-large);
206
+ }
207
+ .flex-end {
208
+ justify-content: flex-end;
209
+ }
210
+ </style>
@@ -19,11 +19,21 @@ const default_routes = [
19
19
  component: () => import("../components/order/item/ItemView.vue"),
20
20
  },
21
21
  {
22
- path: "/shop/basket/",
23
- name: "BasketView",
24
- component: () => import("../components/cart/BasketView.vue"),
22
+ path: "/shop/cart/view",
23
+ name: "CartView",
24
+ component: () => import("../components/cart/CartView.vue"),
25
25
  },
26
- ];
26
+ {
27
+ path: "/shop/order/",
28
+ name: "OrderView",
29
+ component: () => import("../components/order/process/ExampleUsage.vue"),
30
+ },
31
+ {
32
+ path: "/shop/order/confirm",
33
+ name: "ConfirmView",
34
+ component: () => import("../components/cart/ConfirmView.vue"),
35
+ },
36
+ ];4
27
37
 
28
38
  function createRouterInstance(routes, replace = false) {
29
39
  let newRoutes = [];
@@ -1,98 +1,115 @@
1
1
  import { reactive } from "vue";
2
- import { Request } from "@viur/vue-utils";
2
+ import { Request, ListRequest } from "@viur/vue-utils";
3
3
  import { defineStore } from "pinia";
4
4
  import { ViURShopClient } from "@viur/viur-shop-client";
5
5
 
6
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
+
7
14
  const state = reactive({
8
- currentCart: "",
9
- allCarts: {},
10
- cartItems: {},
11
- basketArticle: [],
15
+ basketRootNode: {},
16
+ whishlistRootNodes: [],
17
+ children: {},
18
+ structure: { address: {}, cart: {} },
12
19
  });
13
20
 
14
- function init() {
15
- listCarts().then(async (resp) => {
16
- let data = await resp.json();
17
- getBasket(data);
18
- data.forEach((cart) => {
19
- state.allCarts[cart.key] = cart;
20
- getCartItems(cart.key).then(async (resp) => {
21
- let data = await resp.json();
22
- state.cartItems[cart.key] = data;
23
- });
24
- });
25
- });
21
+ async function init() {
22
+ await getRootNodes();
23
+ }
26
24
 
27
- console.log("hier", state.currentCart);
25
+ async function getChildren(parentKey) {
26
+ let resp = await shopClient.cart_list({ cart_key: parentKey });
28
27
 
29
- getBasketItems(state.currentCart).then(async (resp) => {
30
- let data = await resp.json();
31
- console.log("cartStore basket article", data);
32
- state.basketArticle = data;
33
- });
28
+ return resp
29
+ }
34
30
 
35
- // state.allCarts.forEach((cart) => {
36
- // getCartItems(cart.key).then(async (resp) => {
37
- // let data = await resp.json();
38
- // state.cartItems[cartKey] = data;
39
- // });
40
- // });
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
+ });
41
43
  }
42
44
 
43
- function listCarts() {
44
- return Request.get("/shop/api/cart_list");
45
- // const sc = new ViURShopClient();
45
+ async function addToCart(articleKey, cartKey) {
46
+ let resp = await shopClient.article_add({
47
+ article_key: articleKey,
48
+ parent_cart_key: cartKey,
49
+ });
46
50
 
47
- // sc.cart_list().then(async (resp) => console.log("test", await resp.json));
51
+ await updateCart(cartKey);
52
+ console.log("addToCart", resp); //TODO: Errorhandling as soon as shop module works again
48
53
  }
49
54
 
50
- function getBasket(skellist) {
51
- skellist.forEach((cart) => {
52
- if ((cart.cart_type = "basket")) {
53
- state.currentCart = cart.key;
54
- }
55
+ async function getArticleView(articleKey, cartKey) {
56
+ let article = await shopClient.article_view({
57
+ article_key: articleKey,
58
+ parent_cart_key: cartKey,
55
59
  });
60
+
61
+ console.log("getArticleView", article); // ? Talk about necessarity
56
62
  }
57
63
 
58
- function getBasketItems(cartKey) {
59
- return Request.get(`/shop/api/cart_list`, {
60
- dataObj: { cart_key: cartKey },
64
+ async function removeItem(articleKey, cartKey) {
65
+ let resp = await shopClient.article_remove({
66
+ article_key: articleKey,
67
+ parent_cart_key: cartKey,
61
68
  });
69
+
70
+ console.log("remove Resp", resp); //TODO: Errorhandling as soon as shop module works again
62
71
  }
63
72
 
64
- function getCartItems(cartKey) {
65
- return Request.get(`/shop/api/cart_list`, {
66
- dataObj: { cart_key: cartKey },
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",
67
79
  });
80
+
81
+ if (quantity === 0) {
82
+ await updateCart(cartKey);
83
+ }
84
+ console.log("update Resp", resp); //TODO: Errorhandling as soon as shop module works again
85
+ }
86
+
87
+ async function updateCart(cartKey) {
88
+ await getChildren(cartKey);
68
89
  }
69
90
 
70
- function addToCart(articleKey, cartKey) {
71
- // let skey = "";
72
- // Request.get("/vi/skey?amount=1").then(async (resp) => {
91
+ async function getAdressStructure() {
92
+ let addSkel = await shopClient.address_structure();
93
+ state.structure.address = addSkel.addSkel;
94
+
95
+ console.log("adress add", state.structure.address);
96
+
97
+ // Request.getStructure("shop.address").then(async (resp) => {
73
98
  // let data = await resp.json();
74
- // console.log("skey", data);
75
- // skey = data;
99
+ // state.structure.address = data.addSkel;
100
+
101
+ // console.log("adress add", state.structure.address);
76
102
  // });
77
- Request.securePost("/shop/api/article_add", {
78
- dataObj: {
79
- article_key: articleKey,
80
- parent_cart_key: cartKey,
81
- quantity: 1,
82
- quantity_mode: "increase",
83
- // skey: skey,
84
- },
85
- }).then(async (resp) => {
86
- let data = await resp.json();
87
- console.log("article add", data);
88
- });
89
103
  }
90
104
 
91
105
  return {
92
106
  state,
93
- listCarts,
94
107
  addToCart,
95
- getBasketItems,
108
+ getArticleView,
109
+ removeItem,
110
+ updateItem,
96
111
  init,
112
+ getAdressStructure,
113
+ getChildren,
97
114
  };
98
115
  });
package/src/App.vue DELETED
@@ -1,30 +0,0 @@
1
- <script setup>
2
- import HelloWorld from './components/HelloWorld.vue'
3
- </script>
4
-
5
- <template>
6
- <div>
7
- <a href="https://vitejs.dev" target="_blank">
8
- <img src="/vite.svg" class="logo" alt="Vite logo" />
9
- </a>
10
- <a href="https://vuejs.org/" target="_blank">
11
- <img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
12
- </a>
13
- </div>
14
- <HelloWorld msg="Vite + Vue" />
15
- </template>
16
-
17
- <style scoped>
18
- .logo {
19
- height: 6em;
20
- padding: 1.5em;
21
- will-change: filter;
22
- transition: filter 300ms;
23
- }
24
- .logo:hover {
25
- filter: drop-shadow(0 0 2em #646cffaa);
26
- }
27
- .logo.vue:hover {
28
- filter: drop-shadow(0 0 2em #42b883aa);
29
- }
30
- </style>