@viur/shop-components 0.0.1-dev.6 → 0.0.1-dev.61

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.
Files changed (131) hide show
  1. package/.editorconfig +16 -0
  2. package/.github/workflows/npm-publish.yml +42 -0
  3. package/.gitmodules +3 -0
  4. package/LICENSE +21 -0
  5. package/README.md +13 -2
  6. package/old/client/HttpClient.js +111 -0
  7. package/old/client/ViURShopClient.js +472 -0
  8. package/old/client/index.js +23 -0
  9. package/old/client/types.js +10 -0
  10. package/old/components/ExampleUsage.vue +95 -0
  11. package/old/components/ShopCart.vue +91 -0
  12. package/old/components/ShopOrderComplete.vue +73 -0
  13. package/old/components/ShopOrderConfirm.vue +311 -0
  14. package/old/components/ShopOrderStepper.vue +352 -0
  15. package/old/components/ShopPaymentProvider.vue +113 -0
  16. package/old/components/ShopShippingMethod.vue +52 -0
  17. package/old/components/ShopSummary.vue +138 -0
  18. package/old/components/ShopUserData.vue +218 -0
  19. package/old/components/cart/CartLeaf.vue +277 -0
  20. package/old/components/cart/CartLeafModel.vue +312 -0
  21. package/old/components/cart/CartNode.vue +26 -0
  22. package/old/components/cart/CartTree.vue +67 -0
  23. package/old/components/cart/CartTreeWrapper.vue +73 -0
  24. package/old/components/cart/CartView.vue +82 -0
  25. package/old/components/cart/Discount.vue +91 -0
  26. package/old/components/generic/loadinghandler.vue +76 -0
  27. package/old/components/paymentProvider/paypalplus.vue +0 -0
  28. package/old/components/paymentProvider/prepayment.vue +0 -0
  29. package/old/components/paymentProvider/unzerPayment.vue +140 -0
  30. package/old/components/simple/ShopUserData.vue +161 -0
  31. package/old/components/simple/SimpleDefaultLayout.vue +116 -0
  32. package/old/components/ui/generic/CardSelector.vue +52 -0
  33. package/old/components/ui/generic/CartList.vue +69 -0
  34. package/old/components/ui/generic/ShippingInfo.vue +56 -0
  35. package/old/components/ui/generic/ShopPriceFormatter.vue +41 -0
  36. package/old/components/ui/generic/alerts/ShopAlert.vue +30 -0
  37. package/old/components/ui/payment/PaymentOption.vue +79 -0
  38. package/old/components/ui/payment/PaymentSelector.vue +158 -0
  39. package/old/components/ui/stepper/StepperItem.vue +90 -0
  40. package/old/components/ui/stepper/StepperTab.vue +161 -0
  41. package/old/components/ui/stepper/StepperTrigger.vue +69 -0
  42. package/old/components/ui/userdata/AddForm.vue +160 -0
  43. package/old/components/ui/userdata/AddressBox.vue +137 -0
  44. package/old/components/ui/userdata/BaseLayout.vue +77 -0
  45. package/old/components/ui/userdata/CustomBooleanBone.vue +58 -0
  46. package/old/components/ui/userdata/CustomSelectBone.vue +91 -0
  47. package/old/components/ui/userdata/CustomStringBone.vue +71 -0
  48. package/old/components/ui/userdata/DefaultLayout.vue +126 -0
  49. package/old/components/ui/userdata/SelectAddress.vue +21 -0
  50. package/old/components/ui/userdata/multi/ActionBar.vue +38 -0
  51. package/old/components/ui/userdata/multi/CartSelection.vue +42 -0
  52. package/old/ignite/.editorconfig +20 -0
  53. package/old/ignite/.github/workflows/ignite.yml +64 -0
  54. package/old/ignite/.github/workflows/node.yml +30 -0
  55. package/old/ignite/.postcssrc.cjs +25 -0
  56. package/old/ignite/CHANGELOG.md +244 -0
  57. package/old/ignite/LICENSE +21 -0
  58. package/old/ignite/README.md +92 -0
  59. package/old/ignite/dist/ignite.css +2019 -0
  60. package/old/ignite/dist/ignite.min.css +4 -0
  61. package/old/ignite/foundation/basic.css +371 -0
  62. package/old/ignite/foundation/color.css +323 -0
  63. package/old/ignite/foundation/config.css +188 -0
  64. package/old/ignite/foundation/grid.css +78 -0
  65. package/old/ignite/foundation/mediaqueries.css +71 -0
  66. package/old/ignite/foundation/reset.css +261 -0
  67. package/old/ignite/ignite.css +29 -0
  68. package/old/ignite/ignite.css.map +1 -0
  69. package/old/ignite/package-lock.json +5530 -0
  70. package/old/ignite/package.json +58 -0
  71. package/old/ignite/shoelace.css +19 -0
  72. package/old/ignite/themes/dark.css +12 -0
  73. package/old/ignite/themes/light.css +11 -0
  74. package/old/ignite/utilities/shoelace.css +537 -0
  75. package/old/ignite/utilities/utilities.css +24 -0
  76. package/old/stores/address.js +122 -0
  77. package/old/stores/cart.js +266 -0
  78. package/old/stores/message.js +21 -0
  79. package/old/stores/order.js +202 -0
  80. package/old/stores/payment.js +79 -0
  81. package/old/stores/shipping.js +78 -0
  82. package/package.json +23 -23
  83. package/src/Shop.vue +212 -0
  84. package/src/ShopOrderStepper.vue +89 -0
  85. package/src/ShopSummary.vue +170 -0
  86. package/src/Steps/ShopCart.vue +60 -0
  87. package/src/Steps/ShopOrderComplete.vue +24 -0
  88. package/src/Steps/ShopOrderConfirm.vue +295 -0
  89. package/src/Steps/ShopPaymentProvider.vue +53 -0
  90. package/src/Steps/ShopShippingMethod.vue +53 -0
  91. package/src/Steps/ShopUserDataGuest.vue +78 -0
  92. package/src/Steps/index.js +15 -0
  93. package/src/components/AddressForm.vue +84 -0
  94. package/src/components/AddressFormLayout.vue +107 -0
  95. package/src/components/CardSelector.vue +68 -0
  96. package/src/components/CartItem.vue +325 -0
  97. package/src/components/CartItemSmall.vue +257 -0
  98. package/src/components/LoadingHandler.vue +76 -0
  99. package/src/components/PaymentOption.vue +78 -0
  100. package/src/components/PaymentProviderUnzer.vue +201 -0
  101. package/src/components/PaymentSelector.vue +55 -0
  102. package/src/components/ShopAlert.vue +30 -0
  103. package/src/components/StepperTab.vue +132 -0
  104. package/src/components/dialogButton.vue +49 -0
  105. package/src/composables/address.js +95 -0
  106. package/src/composables/cart.js +132 -0
  107. package/src/composables/order.js +80 -0
  108. package/src/composables/payment.js +75 -0
  109. package/src/composables/shipping.js +32 -0
  110. package/src/main.js +44 -0
  111. package/src/shop.js +251 -0
  112. package/src/translations/de.js +15 -0
  113. package/src/translations/en.js +5 -0
  114. package/src/utils.js +49 -0
  115. package/vite.config.js +51 -0
  116. package/src/components/cart/CartView.vue +0 -692
  117. package/src/components/cart/ConfirmView.vue +0 -314
  118. package/src/components/order/category/CategoryList.vue +0 -83
  119. package/src/components/order/category/CategoryView.vue +0 -143
  120. package/src/components/order/information/UserInfoMulti.vue +0 -427
  121. package/src/components/order/information/UserInformation.vue +0 -332
  122. package/src/components/order/information/adress/ShippingAdress.vue +0 -143
  123. package/src/components/order/item/ItemCard.vue +0 -168
  124. package/src/components/order/item/ItemView.vue +0 -233
  125. package/src/components/order/process/ExampleUsage.vue +0 -100
  126. package/src/components/order/process/OrderComplete.vue +0 -41
  127. package/src/components/order/process/OrderTabHeader.vue +0 -7
  128. package/src/components/order/process/OrderView.vue +0 -210
  129. package/src/router/index.js +0 -103
  130. package/src/stores/cart.js +0 -111
  131. package/src/views/ViewMissing.vue +0 -20
@@ -0,0 +1,122 @@
1
+ import { reactive, computed, watch } from "vue";
2
+ import { defineStore } from "pinia";
3
+ import { struct2dict } from "../lib/utils";
4
+ import { useCartStore } from "./cart";
5
+ export const useAddressStore = defineStore("shop-address", () => {
6
+ const cartStore = useCartStore();
7
+
8
+ const state = reactive({
9
+ shopClient: null,
10
+ addressList: [],
11
+ active: {
12
+ billing: {},
13
+ shipping: {},
14
+ },
15
+ default: { billing: {}, shipping: {} },
16
+ structure: {},
17
+ clone: true,
18
+ });
19
+
20
+ const listByType = (type) => {
21
+ return state.addressList.filter((address) => address.address_type === type);
22
+ };
23
+
24
+ async function getStructure() {
25
+ try {
26
+ const structure = await state.shopClient.address_structure();
27
+
28
+ if (structure.structure) {
29
+ state.structure = struct2dict(structure.structure);
30
+ } else {
31
+ throw error;
32
+ }
33
+ } catch (error) {
34
+ console.error(error);
35
+ }
36
+ }
37
+
38
+ async function init() {
39
+ return new Promise(async (resolve, reject) => {
40
+ if (!cartStore.state.isLoggedIn) {
41
+ reject("not logged in");
42
+ }
43
+ let addressList = [];
44
+ try {
45
+ addressList = await state.shopClient.address_list();
46
+ state.addressList = addressList;
47
+ await getStructure();
48
+ getDefault();
49
+ resolve([state.active.billing, state.active.shipping]);
50
+ } catch (error) {
51
+ reject(error);
52
+ }
53
+ });
54
+ }
55
+
56
+ function getDefault(type = "billing") {
57
+ let list = listByType(type);
58
+
59
+ list.forEach((address) => {
60
+ if (address.is_default) {
61
+ state.default[type] = address;
62
+ state.active[type] = address;
63
+
64
+ if (state.clone) {
65
+ let temp = { ...address };
66
+ temp.address_type = "shipping";
67
+ state.active.shipping = temp;
68
+ }
69
+ }
70
+ });
71
+
72
+ if (!Object.keys(state.default[type]).length) {
73
+ state.active[type] = setValues(type);
74
+ if (state.clone) {
75
+ state.active.shipping = setValues("shipping");
76
+ }
77
+ }
78
+ }
79
+
80
+ function setValues(type) {
81
+ let structure = state.structure;
82
+ let skel = {};
83
+
84
+ Object.entries(structure).forEach(([boneName, boneValue]) => {
85
+ if (boneName === "customer") {
86
+ skel[boneName] = cartStore.state.customer.key;
87
+ } else if (boneName === "address_type") {
88
+ skel[boneName] = type;
89
+ } else {
90
+ skel[boneName] = boneValue.emptyvalue;
91
+ }
92
+ });
93
+
94
+ return skel;
95
+ }
96
+
97
+ function getList(type = "billing") {
98
+ return listByType(type);
99
+ }
100
+
101
+ watch(
102
+ () => state.clone,
103
+ (newValue, oldValue) => {
104
+ if (newValue) {
105
+ let temp = { ...state.active.billing };
106
+ temp.address_type = "shipping";
107
+ state.active.shipping = { ...temp };
108
+ } else {
109
+ getDefault("shipping");
110
+ }
111
+ },
112
+ );
113
+
114
+ return {
115
+ state,
116
+ init,
117
+ setValues,
118
+ getDefault,
119
+ getStructure,
120
+ getList,
121
+ };
122
+ });
@@ -0,0 +1,266 @@
1
+ import { reactive } from "vue";
2
+ import { useUrlSearchParams } from '@vueuse/core'
3
+ import { defineStore } from "pinia";
4
+ import { ViURShopClient } from "../client";
5
+ import { useMessageStore } from "./message";
6
+ import { useOrderStore } from "./order";
7
+ import { useAddressStore } from "./address";
8
+
9
+ /*
10
+ TODO:
11
+ Error Handling. A UI Component (../components/generic/alerts/ShopAlert.vue)
12
+ should be triggered when state.errors has an entry.
13
+ Every Error in this store should be routed into state.errors
14
+ */
15
+ export const useCartStore = defineStore("shop-cart", () => {
16
+ const messageStore = useMessageStore();
17
+ const orderStore = useOrderStore();
18
+ const addressStore = useAddressStore();
19
+
20
+ const state = reactive({
21
+ shopClient: null,
22
+ shopModuleName: "shop",
23
+ currentbasketKey:null,
24
+ basket: {},
25
+ childrenByNode: {},
26
+ paymentProviders: {},
27
+ selectedPaymentProvider: {},
28
+ selectedPaymentProviderName: "",
29
+ customer: {},
30
+ isLoggedIn: false,
31
+ isReady: false,
32
+ isFetching: false,
33
+ hasError: false,
34
+ placeholder: "",
35
+ freeze: false,
36
+ onlyUser: true,
37
+ });
38
+
39
+ function setConfig({
40
+ shopModuleName = "shop",
41
+ placeholder = "",
42
+ onlyUser = true,
43
+ } = {}) {
44
+ /* function set set initial states */
45
+ state.shopModuleName = shopModuleName; // change default module shop to something else
46
+ state.placeholder = placeholder; // define image placeholder for missing images
47
+ state.onlyUser = onlyUser; // define order with or without userAccount
48
+ state.shopClient =
49
+ addressStore.state.shopClient =
50
+ orderStore.state.shopClient =
51
+ new ViURShopClient({
52
+ host_url: import.meta.env.VITE_API_URL
53
+ ? import.meta.env.VITE_API_URL
54
+ : window.location.origin, //use vite config, because all utils requests are using this.
55
+ shop_module: state.shopModuleName, //change default module shop to something else
56
+ });
57
+
58
+ //get Orderkey from url, to continue orderprozess after reload
59
+ const params = useUrlSearchParams('hash')
60
+ if (Object.keys(params).includes('order')){
61
+ orderStore.state.currentOrderkey = params['order']
62
+ }
63
+ }
64
+
65
+ async function init(update = false) {
66
+ console.log("Init Shop");
67
+ if (state.isFetching) {
68
+ return false; // currently we fetch data
69
+ }
70
+ state.isFetching = true;
71
+ if (state.isReady && !update) {
72
+ //block datafetching if shop is ready and no forced update is needed
73
+ return true;
74
+ }
75
+
76
+ try {
77
+ const customer = await getCustomer();
78
+ const loadOrder = await orderStore.getOrder();
79
+ const shopRequests = await Promise.all([
80
+ addressStore.init(),
81
+ getBasket()
82
+ ]);
83
+
84
+ state.isReady = true;
85
+ console.log("%c Shopdata is ready", "color:lime");
86
+ } catch (error) {
87
+ state.isReady = false;
88
+ state.hasError = true;
89
+ console.error(
90
+ "Error: Cant Init because of Error in a essential Shoprequest",
91
+ error,
92
+ );
93
+ messageStore.state.errors.push({
94
+ msg: error,
95
+ variant: "danger",
96
+ iconName: "x-lg",
97
+ id: new Date().getTime(),
98
+ duration: "Infinity",
99
+ closeable: false,
100
+ });
101
+ }
102
+ state.isFetching = false;
103
+ }
104
+
105
+ async function getCustomer() {
106
+ return new Promise(async (resolve, reject) => {
107
+ try {
108
+ const resp = await state.shopClient.user_view();
109
+ state.customer = resp;
110
+ state.isLoggedIn = true;
111
+ resolve(resp);
112
+ } catch (error) {
113
+ state.isLoggedIn = false;
114
+ state.customer = {};
115
+ reject(error);
116
+ }
117
+ });
118
+ }
119
+ async function getBasket(key=null) {
120
+ return new Promise(async (resolve, reject) => {
121
+ if (!key && orderStore.state.currentOrder?.['cart']?.['dest']?.['key']){
122
+ key = orderStore.state.currentOrder['cart']['dest']['key']
123
+ }
124
+ try {
125
+ const resp = await state.shopClient.cart_list({ cart_key: key });
126
+ state.basket = resp[0];
127
+ console.log(orderStore.state.currentOrder)
128
+ console.log(key)
129
+ console.log(state.basket)
130
+ state.currentbasketKey = state.basket?.['parentrepo']?state.basket['parentrepo']:state.basket['key']
131
+ resolve(state.basket);
132
+ } catch (error) {
133
+ state.basket = []; //reset basket on error
134
+ reject(error);
135
+ }
136
+ });
137
+ }
138
+
139
+ async function getOrderCart(){
140
+
141
+ }
142
+
143
+ async function getChildren(parentKey) {
144
+ return await state.shopClient.cart_list({ cart_key: parentKey });
145
+ }
146
+
147
+ async function addToCart(articleKey, cartKey) {
148
+ let resp = await state.shopClient.article_add({
149
+ article_key: articleKey,
150
+ parent_cart_key: cartKey,
151
+ });
152
+ state.basket = await getChildren(cartKey);
153
+ state.currentbasketKey = state.basket['parentrepo']
154
+ }
155
+
156
+ async function removeItem(articleKey, cartKey) {
157
+ try {
158
+ let resp = await state.shopClient.article_remove({
159
+ article_key: articleKey,
160
+ parent_cart_key: cartKey,
161
+ });
162
+ if (resp === null) {
163
+ await updateCart();
164
+ } else {
165
+ throw resp;
166
+ }
167
+ } catch (error) {
168
+ console.log("remove Resp", error); //TODO: Errorhandling as soon as shop module works again
169
+ }
170
+ }
171
+
172
+ async function updateItem(articleKey, cartKey, quantity) {
173
+ const resp = await state.shopClient.article_update({
174
+ article_key: articleKey,
175
+ parent_cart_key: cartKey,
176
+ quantity: quantity,
177
+ quantity_mode: "replace",
178
+ });
179
+
180
+ if (resp) {
181
+ await updateCart();
182
+ }
183
+
184
+ console.log("update Resp", resp); //TODO: Errorhandling as soon as shop module works again
185
+ }
186
+
187
+ async function updateCart() {
188
+ state.basket = {};
189
+ await getBasket();
190
+ }
191
+
192
+ async function addDiscount(code) {
193
+ await state.shopClient.discount_add({ code });
194
+ }
195
+
196
+ async function update({
197
+ key,
198
+ type,
199
+ name,
200
+ customerComment,
201
+ shippingAddress,
202
+ shipping,
203
+ discount,
204
+ } = {}) {
205
+ if (!key) {
206
+ key = state.basket.key;
207
+ }
208
+
209
+ let params = {
210
+ cart_key: key,
211
+ cart_type: type,
212
+ name: name,
213
+ customer_comment: customerComment,
214
+ shipping_address_key: shippingAddress,
215
+ shipping_key: shipping,
216
+ discount_key: discount,
217
+ };
218
+
219
+ try {
220
+ const resp = await state.shopClient.cart_update(params);
221
+ if (resp) {
222
+ console.log("cart update resp", resp);
223
+ } else {
224
+ throw resp;
225
+ }
226
+ } catch (error) {
227
+ console.error("cart.update error", error);
228
+ }
229
+ }
230
+
231
+ // core rc2 needed to work with all parameters
232
+ async function addNode(
233
+ parentCart,
234
+ cartType = "whishlist",
235
+ cartName = undefined,
236
+ comment = undefined,
237
+ shipping_key = undefined,
238
+ shipping_address_key = undefined,
239
+ discount_key = undefined,
240
+ ) {
241
+ return await state.shopClient.cart_add({
242
+ parent_cart_key: parentCart,
243
+ cart_type: cartType, // "basket" for main cart, "whishlist" for everything else
244
+ name: cartName,
245
+ customer_comment: comment,
246
+ shipping_address_key: shipping_address_key,
247
+ shipping_key: shipping_key,
248
+ discount_key: discount_key,
249
+ });
250
+ }
251
+
252
+
253
+ return {
254
+ state,
255
+ setConfig,
256
+ addToCart,
257
+ removeItem,
258
+ updateItem,
259
+ init,
260
+ getChildren,
261
+ addDiscount,
262
+ addNode,
263
+ getBasket,
264
+ update,
265
+ };
266
+ });
@@ -0,0 +1,21 @@
1
+ import { reactive, computed } from "vue";
2
+ import { defineStore } from "pinia";
3
+
4
+ export const useMessageStore = defineStore("shop-message", () => {
5
+ const state = reactive({
6
+ errors: [],
7
+ blacklist: [],
8
+ });
9
+
10
+ const errorCounter = computed(() => state.errors.length);
11
+
12
+ function reset() {
13
+ state.errors = [];
14
+ }
15
+
16
+ return {
17
+ state,
18
+ reset,
19
+ errorCounter,
20
+ };
21
+ });
@@ -0,0 +1,202 @@
1
+ import { reactive } from "vue";
2
+ import { defineStore } from "pinia";
3
+ import { useCartStore } from "./cart";
4
+ import { useMessageStore } from "./message";
5
+ import { Request } from '@viur/vue-utils'
6
+ import { useUrlSearchParams } from '@vueuse/core'
7
+
8
+ export const useOrderStore = defineStore("shop-order", () => {
9
+ const cartStore = useCartStore();
10
+ const messageStore = useMessageStore();
11
+
12
+ const state = reactive({
13
+ currentOrderkey:null,
14
+ currentOrder: null,
15
+ shopClient: undefined,
16
+ updateParams: {},
17
+ paramsChanged: false,
18
+ checkoutState: null, // null "prepare","start", ...
19
+ checkout: null,
20
+ });
21
+
22
+ function getOrder(){
23
+ return new Promise(async (resolve, reject) => {
24
+ if (!state.currentOrderkey){
25
+ resolve()
26
+ }
27
+ try{
28
+ const response = await Request.post(state.shopClient.shop_api_url+"/order_view",{dataObj:{
29
+ "order_key": state.currentOrderkey
30
+ }})
31
+
32
+
33
+ console.log(response)
34
+ const data = await response.json()
35
+ console.log(data['skel'])
36
+ state.currentOrder = data['skel']
37
+
38
+ } catch(error){
39
+ state.currentOrder = null
40
+ }
41
+ resolve()
42
+ })
43
+ }
44
+
45
+ function add(obj) {
46
+ return new Promise((resolve, reject) => {
47
+ state.shopClient
48
+ .order_add(obj)
49
+ .then(async (resp) => {
50
+ let data = await resp;
51
+ state.currentOrder = data;
52
+ state.currentOrderkey = data["key"]
53
+ const params = useUrlSearchParams('hash')
54
+ params['order'] = state.currentOrderkey
55
+ resolve(data);
56
+ })
57
+ .catch((error) => {
58
+ messageStore.state.errors.push({
59
+ msg: error,
60
+ variant: "danger",
61
+ iconName: "x-lg",
62
+ id: new Date().getTime(),
63
+ duration: "Infinity",
64
+ closeable: false,
65
+ });
66
+ reject(error);
67
+ });
68
+ });
69
+ }
70
+
71
+ function update() {
72
+ Object.assign(state.updateParams, {
73
+ order_key: state.currentOrder.key,
74
+ });
75
+
76
+ return new Promise((resolve, reject) => {
77
+ state.shopClient
78
+ .order_update(state.updateParams)
79
+ .then(async (resp) => {
80
+ let data = await resp;
81
+ state.currentOrder = data;
82
+ state.currentOrderkey = data["key"]
83
+ state.paramsChanged = false;
84
+ resolve(data);
85
+ })
86
+ .catch((error) => {
87
+ messageStore.state.errors.push({
88
+ msg: error,
89
+ variant: "danger",
90
+ iconName: "x-lg",
91
+ id: new Date().getTime(),
92
+ duration: "Infinity",
93
+ closeable: false,
94
+ });
95
+ reject(error);
96
+ });
97
+ });
98
+ }
99
+
100
+ function getExistingOrder() {
101
+ // needs clarification
102
+ }
103
+
104
+ function updateParams(obj = {}) {
105
+ if (!Object.keys(obj).length) {
106
+ return;
107
+ }
108
+
109
+ for (let [k, v] of Object.entries(obj)) {
110
+ if (state.updateParams?.[k] !== v) {
111
+ Object.assign(state.updateParams, obj);
112
+ state.paramsChanged = true;
113
+ return;
114
+ }
115
+ }
116
+ }
117
+
118
+ function handler() {
119
+ /* Accepted Parameters
120
+ (*** required fields; only 1 of the required fields need to be set)
121
+ obj = {
122
+ cart_key: "key",
123
+ payment_provider: "payment_provider key",
124
+ billing_address_key: "billing_address_key",
125
+ email: "email", ***
126
+ customer_key: "customer_key", ***
127
+ state_ordered: "state",
128
+ state_paid: "state",
129
+ state_rts: "state",
130
+ }; */
131
+
132
+ if (
133
+ !(
134
+ state.updateParams &&
135
+ (state.updateParams.email || state.updateParams.customer_key)
136
+ )
137
+ ) {
138
+ state.updateParams.customer_key = cartStore.state.customer.key;
139
+ }
140
+
141
+ if (!state.currentOrder) {
142
+ // TODO: getExistingOrder().then(state.currentOrder = value).error(add(params)...)
143
+
144
+ if (!state.updateParams.cart_key) {
145
+ state.updateParams.cart_key = cartStore.state.basket.key;
146
+ }
147
+
148
+ add(state.updateParams);
149
+ } else {
150
+ if (state.paramsChanged) {
151
+ update();
152
+ }
153
+ }
154
+ }
155
+
156
+ function add_or_update(){
157
+ if (
158
+ !(
159
+ state.updateParams &&
160
+ (state.updateParams.email || state.updateParams.customer_key)
161
+ )
162
+ ) {
163
+ state.updateParams.customer_key = cartStore.state.customer.key;
164
+ }
165
+
166
+ if (!state.currentOrder) {
167
+ // TODO: getExistingOrder().then(state.currentOrder = value).error(add(params)...)
168
+
169
+ if (!state.updateParams.cart_key) {
170
+ state.updateParams.cart_key = cartStore.state.basket.key;
171
+ }
172
+
173
+ add(state.updateParams);
174
+ } else {
175
+ if (state.paramsChanged) {
176
+ update();
177
+ }
178
+ }
179
+ }
180
+
181
+
182
+ async function startCheckout() {
183
+ try {
184
+ state.checkout = await state.shopClient.order_checkout_start({
185
+ order_key: state.currentOrder.key,
186
+ });
187
+ cartStore.state.freeze = true;
188
+ } catch (error) {
189
+ console.log(state.checkout);
190
+ console.dir(error);
191
+ }
192
+ }
193
+
194
+ return {
195
+ state,
196
+ handler,
197
+ startCheckout,
198
+ updateParams,
199
+ getOrder,
200
+ add_or_update
201
+ };
202
+ });
@@ -0,0 +1,79 @@
1
+ import { reactive, computed, watch } from "vue";
2
+ import { defineStore } from "pinia";
3
+ import { Request } from "@viur/vue-utils";
4
+ import { useCartStore } from "./cart";
5
+ import { useOrderStore } from './order'
6
+
7
+ export const usePaymentStore = defineStore("payment-shipping", () => {
8
+ const cartStore = useCartStore()
9
+ const orderStore = useOrderStore()
10
+
11
+ const state = reactive({
12
+ paymentProviders: [], //payment options
13
+ paymentInstances:[],
14
+ paymentSelection:null,
15
+ isLoading:false,
16
+ isUpdating:false,
17
+ hasError:false,
18
+ errorMessage:"",
19
+ init:true, //fetch onMount and store is ready
20
+ paymentHandler:{}
21
+ })
22
+
23
+ async function getPaymentProviders() {
24
+ state.paymentSelection = null
25
+ state.isLoading = true
26
+ state.isUpdating = false
27
+ state.hasError = false
28
+ try{
29
+ let providersObject = await cartStore.state.shopClient.payment_providers_list()
30
+ state.paymentProviders = Object.entries(providersObject) // cardselector needs a list
31
+ state.isLoading = false
32
+ if(state.paymentProviders.length===0){
33
+ state.hasError = true
34
+ state.errorMessage = "Keine gültige Bezahlart gefunden."
35
+ }
36
+ } catch (error) {
37
+ console.log(error)
38
+ state.isLoading = false
39
+ state.hasError = true
40
+ state.errorMessage = "Keine gültige Bezahlart gefunden."
41
+ }
42
+ }
43
+
44
+ async function initPayment(){
45
+ if (!state.init) return false
46
+ await cartStore.init() // ensure store config starts loading
47
+ if (!orderStore.state.currentOrder || Object.keys(orderStore.state.currentOrder).length===0){
48
+ /*
49
+ state.hasError = true
50
+ state.errorMessage = "Keine gültige Bestellung gefunden"
51
+ return false */
52
+ } // we need a valid order
53
+
54
+
55
+ if (cartStore.state.isReady){
56
+ await getPaymentProviders() // request Payment data based on current cart
57
+ }
58
+ return true
59
+ }
60
+
61
+ function updateOrder(){
62
+ console.log("updateOrder payment", orderStore.state.currentOrder)
63
+ orderStore.updateParams({
64
+ payment_provider: state.paymentSelection[0]
65
+ })
66
+ return true
67
+ }
68
+
69
+ watch(()=>cartStore.state.isReady, async(newVal, oldVal)=>{
70
+ await initPayment() // auto fetch if shop is ready
71
+ })
72
+
73
+ return {
74
+ state,
75
+ getPaymentProviders,
76
+ initPayment,
77
+ updateOrder
78
+ }
79
+ })