@viur/shop-components 0.0.1-dev.2 → 0.0.1-dev.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.
@@ -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,111 @@
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: window.location.origin === "http://localhost:8081"
9
+ ? "http://localhost:8080"
10
+ : window.location.origin,
11
+ });
12
+
7
13
  const state = reactive({
8
- currentCart: "",
9
- allCarts: {},
10
- cartItems: {},
11
- basketArticle: [],
14
+ basket: "",
15
+ carts: {},
16
+ structure: { address: {}, cart: {} },
12
17
  });
13
18
 
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
- });
19
+ async function init() {
20
+ await getCarts();
21
+ }
22
+
23
+ async function getCarts() {
24
+ let carts = await shopClient.cart_list();
25
+ carts.forEach(async (cart) => {
26
+ state.carts[cart.key] = {};
27
+ state.carts[cart.key].info = cart;
28
+ if (cart.cart_type === "basket") {
29
+ state.basket = cart.key;
30
+ }
31
+ await getCartItems(cart.key);
25
32
  });
33
+ }
26
34
 
27
- console.log("hier", state.currentCart);
35
+ async function getCartItems(cartKey) {
36
+ let cartItems = await shopClient.cart_list({ cart_key: cartKey });
37
+ state.carts[cartKey].items = cartItems;
38
+ }
28
39
 
29
- getBasketItems(state.currentCart).then(async (resp) => {
30
- let data = await resp.json();
31
- console.log("cartStore basket article", data);
32
- state.basketArticle = data;
40
+ async function addToCart(articleKey, cartKey) {
41
+ let resp = await shopClient.article_add({
42
+ article_key: articleKey,
43
+ parent_cart_key: cartKey,
33
44
  });
34
45
 
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
- // });
46
+ await updateCart(cartKey);
47
+ console.log("addToCart", resp); //TODO: Errorhandling as soon as shop module works again
41
48
  }
42
49
 
43
- function listCarts() {
44
- return Request.get("/shop/api/cart_list");
45
- // const sc = new ViURShopClient();
50
+ async function getArticleView(articleKey, cartKey) {
51
+ let article = await shopClient.article_view({
52
+ article_key: articleKey,
53
+ parent_cart_key: cartKey,
54
+ });
46
55
 
47
- // sc.cart_list().then(async (resp) => console.log("test", await resp.json));
56
+ console.log("getArticleView", article); // ? Talk about necessarity
48
57
  }
49
58
 
50
- function getBasket(skellist) {
51
- skellist.forEach((cart) => {
52
- if ((cart.cart_type = "basket")) {
53
- state.currentCart = cart.key;
54
- }
59
+ async function removeItem(articleKey, cartKey) {
60
+ let resp = await shopClient.article_remove({
61
+ article_key: articleKey,
62
+ parent_cart_key: cartKey,
55
63
  });
64
+
65
+ await updateCart(cartKey);
66
+
67
+ console.log("remove Resp", resp); //TODO: Errorhandling as soon as shop module works again
56
68
  }
57
69
 
58
- function getBasketItems(cartKey) {
59
- return Request.get(`/shop/api/cart_list`, {
60
- dataObj: { cart_key: cartKey },
70
+ async function updateItem(articleKey, cartKey, quantity) {
71
+ let resp = await shopClient.article_update({
72
+ article_key: articleKey,
73
+ parent_cart_key: cartKey,
74
+ quantity: quantity,
75
+ quantity_mode: "replace",
61
76
  });
77
+
78
+ if (quantity === 0) {
79
+ await updateCart(cartKey);
80
+ }
81
+ console.log("update Resp", resp); //TODO: Errorhandling as soon as shop module works again
62
82
  }
63
83
 
64
- function getCartItems(cartKey) {
65
- return Request.get(`/shop/api/cart_list`, {
66
- dataObj: { cart_key: cartKey },
67
- });
84
+ async function updateCart(cartKey) {
85
+ await getCartItems(cartKey);
68
86
  }
69
87
 
70
- function addToCart(articleKey, cartKey) {
71
- // let skey = "";
72
- // Request.get("/vi/skey?amount=1").then(async (resp) => {
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) => {
73
95
  // let data = await resp.json();
74
- // console.log("skey", data);
75
- // skey = data;
96
+ // state.structure.address = data.addSkel;
97
+
98
+ // console.log("adress add", state.structure.address);
76
99
  // });
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
100
  }
90
101
 
91
102
  return {
92
103
  state,
93
- listCarts,
94
104
  addToCart,
95
- getBasketItems,
105
+ getArticleView,
106
+ removeItem,
107
+ updateItem,
96
108
  init,
109
+ getAdressStructure,
97
110
  };
98
111
  });
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>