@viur/shop-components 0.0.1-dev.60 → 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.
- package/old/client/HttpClient.js +111 -0
- package/old/client/ViURShopClient.js +472 -0
- package/old/client/index.js +23 -0
- package/old/client/types.js +10 -0
- package/old/components/ExampleUsage.vue +95 -0
- package/old/components/ShopCart.vue +91 -0
- package/old/components/ShopOrderConfirm.vue +311 -0
- package/{src → old}/components/ShopOrderStepper.vue +111 -23
- package/old/components/ShopPaymentProvider.vue +113 -0
- package/old/components/ShopShippingMethod.vue +52 -0
- package/{src/components/ui → old/components}/ShopSummary.vue +28 -35
- package/{src → old}/components/ShopUserData.vue +51 -65
- package/{src → old}/components/cart/CartLeafModel.vue +24 -16
- package/{src → old}/components/cart/CartNode.vue +1 -0
- package/{src → old}/components/cart/CartTree.vue +13 -0
- package/old/components/cart/CartView.vue +82 -0
- package/{src → old}/components/cart/Discount.vue +8 -8
- package/old/components/generic/loadinghandler.vue +76 -0
- package/old/components/paymentProvider/prepayment.vue +0 -0
- package/old/components/paymentProvider/unzerPayment.vue +140 -0
- package/old/components/simple/ShopUserData.vue +161 -0
- package/old/components/simple/SimpleDefaultLayout.vue +116 -0
- package/old/components/ui/generic/CardSelector.vue +52 -0
- package/old/components/ui/generic/CartList.vue +69 -0
- package/old/components/ui/generic/ShippingInfo.vue +56 -0
- package/old/components/ui/generic/alerts/ShopAlert.vue +30 -0
- package/old/components/ui/payment/PaymentOption.vue +79 -0
- package/old/components/ui/payment/PaymentSelector.vue +158 -0
- package/old/components/ui/stepper/StepperItem.vue +90 -0
- package/{src → old}/components/ui/stepper/StepperTab.vue +30 -2
- package/old/components/ui/stepper/StepperTrigger.vue +69 -0
- package/old/components/ui/userdata/AddForm.vue +160 -0
- package/old/components/ui/userdata/AddressBox.vue +137 -0
- package/{src → old}/components/ui/userdata/BaseLayout.vue +15 -32
- package/old/stores/address.js +122 -0
- package/old/stores/cart.js +266 -0
- package/old/stores/message.js +21 -0
- package/old/stores/order.js +202 -0
- package/old/stores/payment.js +79 -0
- package/old/stores/shipping.js +78 -0
- package/package.json +3 -5
- package/src/Shop.vue +212 -0
- package/src/ShopOrderStepper.vue +89 -0
- package/src/ShopSummary.vue +170 -0
- package/src/Steps/ShopCart.vue +60 -0
- package/src/Steps/ShopOrderComplete.vue +24 -0
- package/src/Steps/ShopOrderConfirm.vue +295 -0
- package/src/Steps/ShopPaymentProvider.vue +53 -0
- package/src/Steps/ShopShippingMethod.vue +53 -0
- package/src/Steps/ShopUserDataGuest.vue +78 -0
- package/src/Steps/index.js +15 -0
- package/src/components/AddressForm.vue +84 -0
- package/src/components/AddressFormLayout.vue +107 -0
- package/src/components/CardSelector.vue +68 -0
- package/src/components/CartItem.vue +325 -0
- package/src/components/CartItemSmall.vue +257 -0
- package/src/components/LoadingHandler.vue +76 -0
- package/src/components/PaymentOption.vue +78 -0
- package/src/components/PaymentProviderUnzer.vue +201 -0
- package/src/components/PaymentSelector.vue +55 -0
- package/src/components/ShopAlert.vue +30 -0
- package/src/components/StepperTab.vue +132 -0
- package/src/components/dialogButton.vue +49 -0
- package/src/composables/address.js +95 -0
- package/src/composables/cart.js +132 -0
- package/src/composables/order.js +80 -0
- package/src/composables/payment.js +75 -0
- package/src/composables/shipping.js +32 -0
- package/src/main.js +32 -38
- package/src/shop.js +251 -0
- package/src/translations/de.js +15 -0
- package/src/translations/en.js +5 -0
- package/src/utils.js +49 -0
- package/vite.config.js +0 -2
- package/src/components/ShopCart.vue +0 -512
- package/src/components/ShopOrderConfirm.vue +0 -291
- package/src/components/cart/CartView.vue +0 -723
- package/src/components/order/OrderSidebar.vue +0 -102
- package/src/components/order/category/CategoryList.vue +0 -83
- package/src/components/order/category/CategoryView.vue +0 -143
- package/src/components/order/information/adress/ShippingAdress.vue +0 -143
- package/src/components/order/item/ItemCard.vue +0 -168
- package/src/components/order/item/ItemView.vue +0 -232
- package/src/components/order/process/ConfirmView.vue +0 -312
- package/src/components/order/process/ExampleUsage.vue +0 -113
- package/src/components/order/process/OrderTabHeader.vue +0 -16
- package/src/components/order/process/SelectPaymentProvider.vue +0 -62
- package/src/components/order/process/Shipping.vue +0 -46
- package/src/components/ui/generic/ArticleList.vue +0 -222
- package/src/components/ui/generic/ExamplePagination.vue +0 -236
- package/src/components/ui/generic/alerts/ShopAlert.vue +0 -19
- package/src/components/ui/generic/makeData.js +0 -39
- package/src/components/ui/stepper/StepperItem.vue +0 -39
- package/src/components/ui/stepper/StepperTrigger.vue +0 -35
- package/src/components/ui/userdata/AddForm.vue +0 -125
- package/src/components/ui/userdata/AddressBox.vue +0 -117
- package/src/router/index.js +0 -103
- package/src/stores/cart.js +0 -336
- package/src/views/ViewMissing.vue +0 -20
- /package/{src → old}/components/ShopOrderComplete.vue +0 -0
- /package/{src → old}/components/cart/CartLeaf.vue +0 -0
- /package/{src → old}/components/cart/CartTreeWrapper.vue +0 -0
- /package/{src/components/lib/utils.js → old/components/paymentProvider/paypalplus.vue} +0 -0
- /package/{src → old}/components/ui/generic/ShopPriceFormatter.vue +0 -0
- /package/{src → old}/components/ui/userdata/CustomBooleanBone.vue +0 -0
- /package/{src → old}/components/ui/userdata/CustomSelectBone.vue +0 -0
- /package/{src → old}/components/ui/userdata/CustomStringBone.vue +0 -0
- /package/{src → old}/components/ui/userdata/DefaultLayout.vue +0 -0
- /package/{src → old}/components/ui/userdata/SelectAddress.vue +0 -0
- /package/{src → old}/components/ui/userdata/multi/ActionBar.vue +0 -0
- /package/{src → old}/components/ui/userdata/multi/CartSelection.vue +0 -0
- /package/{src/style → old}/ignite/.editorconfig +0 -0
- /package/{src/style → old}/ignite/.github/workflows/ignite.yml +0 -0
- /package/{src/style → old}/ignite/.github/workflows/node.yml +0 -0
- /package/{src/style → old}/ignite/.postcssrc.cjs +0 -0
- /package/{src/style → old}/ignite/CHANGELOG.md +0 -0
- /package/{src/style → old}/ignite/LICENSE +0 -0
- /package/{src/style → old}/ignite/README.md +0 -0
- /package/{src/style → old}/ignite/dist/ignite.css +0 -0
- /package/{src/style → old}/ignite/dist/ignite.min.css +0 -0
- /package/{src/style → old}/ignite/foundation/basic.css +0 -0
- /package/{src/style → old}/ignite/foundation/color.css +0 -0
- /package/{src/style → old}/ignite/foundation/config.css +0 -0
- /package/{src/style → old}/ignite/foundation/grid.css +0 -0
- /package/{src/style → old}/ignite/foundation/mediaqueries.css +0 -0
- /package/{src/style → old}/ignite/foundation/reset.css +0 -0
- /package/{src/style → old}/ignite/ignite.css +0 -0
- /package/{src/style → old}/ignite/ignite.css.map +0 -0
- /package/{src/style → old}/ignite/package-lock.json +0 -0
- /package/{src/style → old}/ignite/package.json +0 -0
- /package/{src/style → old}/ignite/shoelace.css +0 -0
- /package/{src/style → old}/ignite/themes/dark.css +0 -0
- /package/{src/style → old}/ignite/themes/light.css +0 -0
- /package/{src/style → old}/ignite/utilities/shoelace.css +0 -0
- /package/{src/style → old}/ignite/utilities/utilities.css +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="viur-shop-address-box">
|
|
3
|
+
<select-address
|
|
4
|
+
v-if="addressSelection"
|
|
5
|
+
:address-list="state.addressList"
|
|
6
|
+
:modelValue="
|
|
7
|
+
type === 'billing'
|
|
8
|
+
? addressStore.state.active.billing.key
|
|
9
|
+
: addressStore.state.active.shipping.key
|
|
10
|
+
"
|
|
11
|
+
@update:modelValue="handleSelection"
|
|
12
|
+
>
|
|
13
|
+
</select-address>
|
|
14
|
+
|
|
15
|
+
<!-- debugging -->
|
|
16
|
+
<!-- {{ mode === "billing" ? addressStore.state.activeBillingAddress : "" }} -->
|
|
17
|
+
<!-- {{ mode === "billing" ? "" : addressStore.state.activeShippingAddress }} -->
|
|
18
|
+
<!-- <pre>{{ customer }}</pre> -->
|
|
19
|
+
|
|
20
|
+
<div class="viur-shop-address-box-preview" v-if="state.address">
|
|
21
|
+
<span>Ausgewählte Adresse :</span>
|
|
22
|
+
<br />
|
|
23
|
+
{{ state.address?.street_name }} {{ state.address?.street_number }}<br />
|
|
24
|
+
{{ state.address?.zip_code }} {{ state.address?.city }}
|
|
25
|
+
<br />
|
|
26
|
+
{{ state.address?.country }}
|
|
27
|
+
<br />
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script setup>
|
|
33
|
+
import { reactive, computed, onBeforeMount, watch } from "vue";
|
|
34
|
+
import { useAddressStore } from "../../../stores/address";
|
|
35
|
+
import { useOrderStore } from "../../../stores/order";
|
|
36
|
+
import { useCartStore } from "../../../stores/cart";
|
|
37
|
+
import SelectAddress from "./SelectAddress.vue";
|
|
38
|
+
|
|
39
|
+
const props = defineProps({
|
|
40
|
+
type: { type: String, default: "billing" },
|
|
41
|
+
addressSelection: { type: Boolean, default: false },
|
|
42
|
+
modelValue: { type: Object },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const emit = defineEmits(["update:modelValue", "valid"]);
|
|
46
|
+
|
|
47
|
+
const addressStore = useAddressStore();
|
|
48
|
+
const orderStore = useOrderStore();
|
|
49
|
+
const cartStore = useCartStore();
|
|
50
|
+
|
|
51
|
+
const state = reactive({
|
|
52
|
+
addressList: computed(() =>
|
|
53
|
+
props.type === "billing"
|
|
54
|
+
? addressStore.getList()
|
|
55
|
+
: addressStore.getList("shipping"),
|
|
56
|
+
),
|
|
57
|
+
address: computed(() => {
|
|
58
|
+
return props.type === "billing"
|
|
59
|
+
? addressStore.state.active.billing
|
|
60
|
+
: addressStore.state.active.shipping;
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
function isValid() {
|
|
65
|
+
if (props.type === "billing") {
|
|
66
|
+
if (addressStore.state.active.billing.key) {
|
|
67
|
+
orderStore.updateParams({
|
|
68
|
+
billing_address_key: addressStore.state.active.billing.key,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
if (addressStore.state.clone) {
|
|
72
|
+
cartStore.update({
|
|
73
|
+
key: orderStore.state.currentOrder
|
|
74
|
+
? orderStore.state.currentOrder.cart.dest.key
|
|
75
|
+
: cartStore.state.basket.key,
|
|
76
|
+
shippingAddress: addressStore.state.active.shipping.key,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
emit("valid", true);
|
|
81
|
+
} else {
|
|
82
|
+
emit("valid", false);
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
if (addressStore.state.active.shipping.key) {
|
|
86
|
+
cartStore.update({
|
|
87
|
+
key: orderStore.state.currentOrder.cart.dest.key,
|
|
88
|
+
shippingAddress: addressStore.state.active.shipping.key,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
emit("valid", true);
|
|
92
|
+
} else {
|
|
93
|
+
emit("valid", false);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function handleSelection(e) {
|
|
99
|
+
let address = state.addressList.filter((address) => address.key === e);
|
|
100
|
+
|
|
101
|
+
if (props.type === "billing") {
|
|
102
|
+
addressStore.state.active.billing = address[0];
|
|
103
|
+
|
|
104
|
+
orderStore.updateParams({
|
|
105
|
+
billing_address_key: addressStore.state.active.billing.key,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (addressStore.state.clone) {
|
|
109
|
+
cartStore.update({
|
|
110
|
+
key: orderStore.state.currentOrder.cart.dest.key,
|
|
111
|
+
shippingAddress: addressStore.state.active.shipping.key,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
emit("valid", true);
|
|
116
|
+
} else {
|
|
117
|
+
addressStore.state.active.shipping = address[0];
|
|
118
|
+
|
|
119
|
+
cartStore.update({
|
|
120
|
+
key: orderStore.state.currentOrder.cart.dest.key,
|
|
121
|
+
shippingAddress: addressStore.state.active.shipping.key,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
emit("valid", true);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
onBeforeMount(() => {
|
|
129
|
+
isValid();
|
|
130
|
+
});
|
|
131
|
+
</script>
|
|
132
|
+
|
|
133
|
+
<style scoped>
|
|
134
|
+
.viur-shop-address-box-preview {
|
|
135
|
+
margin: var(--sl-spacing-medium) 0;
|
|
136
|
+
}
|
|
137
|
+
</style>
|
|
@@ -12,37 +12,30 @@
|
|
|
12
12
|
<div class="viur-shop-cart-address">
|
|
13
13
|
<div class="viur-shop-cart-address-headline">
|
|
14
14
|
{{ $t("skeleton.address.address_type.billing") }}
|
|
15
|
-
<sl-button outline size="small" @click="editBilling">
|
|
16
|
-
<sl-icon name="pencil" slot="prefix"></sl-icon>
|
|
17
|
-
</sl-button>
|
|
18
15
|
</div>
|
|
16
|
+
|
|
19
17
|
<slot name="billing-address">
|
|
20
|
-
<address-box
|
|
18
|
+
<address-box
|
|
19
|
+
:address-selection="true"
|
|
20
|
+
:type="'billing'"
|
|
21
|
+
@valid="emit('valid', $event)"
|
|
22
|
+
>
|
|
23
|
+
</address-box>
|
|
21
24
|
</slot>
|
|
22
25
|
</div>
|
|
26
|
+
|
|
23
27
|
<slot name="mode-switch"></slot>
|
|
28
|
+
|
|
24
29
|
<div class="viur-shop-cart-address" v-if="customAddress">
|
|
25
30
|
<div class="viur-shop-cart-address-headline">
|
|
26
31
|
{{ $t("skeleton.address.address_type.shipping") }}
|
|
27
|
-
<sl-button
|
|
28
|
-
outline
|
|
29
|
-
size="small"
|
|
30
|
-
@click="editShipping"
|
|
31
|
-
v-if="customAddress"
|
|
32
|
-
>
|
|
33
|
-
<sl-icon name="pencil" slot="prefix"></sl-icon>
|
|
34
|
-
</sl-button>
|
|
35
32
|
</div>
|
|
33
|
+
|
|
36
34
|
<slot name="shipping-address" v-if="customAddress">
|
|
37
35
|
<address-box
|
|
38
|
-
:address-selection="
|
|
39
|
-
:
|
|
40
|
-
|
|
41
|
-
</slot>
|
|
42
|
-
<slot name="shipping-address" v-else>
|
|
43
|
-
<address-box
|
|
44
|
-
:address-selection="true && customAddress"
|
|
45
|
-
:mode="'billing'"
|
|
36
|
+
:address-selection="customAddress"
|
|
37
|
+
:type="'shipping'"
|
|
38
|
+
@valid="emit('valid', $event)"
|
|
46
39
|
>
|
|
47
40
|
</address-box>
|
|
48
41
|
</slot>
|
|
@@ -52,7 +45,6 @@
|
|
|
52
45
|
|
|
53
46
|
<script setup>
|
|
54
47
|
import { reactive } from "vue";
|
|
55
|
-
import { useCartStore } from "../../../stores/cart";
|
|
56
48
|
import AddressBox from "./AddressBox.vue";
|
|
57
49
|
|
|
58
50
|
const props = defineProps({
|
|
@@ -60,18 +52,9 @@ const props = defineProps({
|
|
|
60
52
|
customAddress: { type: Boolean, default: false },
|
|
61
53
|
});
|
|
62
54
|
|
|
63
|
-
const emit = defineEmits(["
|
|
64
|
-
const state = reactive({ editBilling: false, editShipping: false });
|
|
55
|
+
const emit = defineEmits(["valid"]);
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
state.editBilling = !state.editBilling;
|
|
68
|
-
emit("editBilling", state.editBilling);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function editShipping() {
|
|
72
|
-
state.editShipping = !state.editShipping;
|
|
73
|
-
emit("editShipping", state.editShipping);
|
|
74
|
-
}
|
|
57
|
+
const state = reactive({ });
|
|
75
58
|
</script>
|
|
76
59
|
|
|
77
60
|
<style scoped>
|
|
@@ -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
|
+
});
|