@viur/shop-components 0.1.21 → 0.2.1
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/package.json +1 -1
- package/src/Shop.vue +4 -7
- package/src/ShopOrderStepper.vue +3 -23
- package/src/ShopSummary.vue +10 -1
- package/src/Steps/ShopShippingMethod.vue +11 -6
- package/src/components/CartItemSmall.vue +1 -1
- package/src/components/PaymentProviderUnzer.vue +1 -3
- package/src/components/StepperTab.vue +7 -1
- package/src/composables/address.js +108 -87
- package/src/composables/cart.js +10 -6
- package/src/composables/order.js +18 -13
- package/src/composables/payment.js +3 -2
- package/src/composables/shipping.js +42 -36
- package/src/shop.js +40 -13
package/package.json
CHANGED
package/src/Shop.vue
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<div class="viur-shop-stepper-wrap"
|
|
4
4
|
:class="{ 'full-width': (!summary || summary==='bottom' || shopStore.state.currentTab==='complete') }"
|
|
5
5
|
>
|
|
6
|
-
<shop-order-stepper>
|
|
6
|
+
<shop-order-stepper >
|
|
7
7
|
<template #template_cart>
|
|
8
8
|
<slot name="template_cart"></slot>
|
|
9
9
|
</template>
|
|
@@ -213,11 +213,6 @@ watch(()=>shopStore.state.currentTab, (newVal,oldVal)=>{
|
|
|
213
213
|
display: flex;
|
|
214
214
|
flex-direction: column;
|
|
215
215
|
grid-column: auto / span 12;
|
|
216
|
-
|
|
217
|
-
&.full-width {
|
|
218
|
-
grid-column: auto / span 12;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
216
|
@media (min-width: 1024px) {
|
|
222
217
|
grid-column: auto / span var(--shop-main-columns);
|
|
223
218
|
}
|
|
@@ -252,7 +247,9 @@ watch(()=>shopStore.state.currentTab, (newVal,oldVal)=>{
|
|
|
252
247
|
grid-row-start: 2;
|
|
253
248
|
}
|
|
254
249
|
|
|
255
|
-
|
|
250
|
+
.full-width {
|
|
251
|
+
grid-column: auto / span 12;
|
|
252
|
+
}
|
|
256
253
|
|
|
257
254
|
.last-row {
|
|
258
255
|
grid-row-start: 3;
|
package/src/ShopOrderStepper.vue
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
ref="stepper"
|
|
6
6
|
>
|
|
7
7
|
<template v-for="(tab,name) in shopStore.state.tabs">
|
|
8
|
-
<StepperTab
|
|
8
|
+
<StepperTab v-show="shopStore.state.currentTab!=='complete'"
|
|
9
9
|
:tab="name"
|
|
10
10
|
>
|
|
11
11
|
</StepperTab>
|
|
@@ -89,26 +89,7 @@ onMounted(()=>{
|
|
|
89
89
|
})
|
|
90
90
|
|
|
91
91
|
function nextStep(obj){
|
|
92
|
-
shopStore.
|
|
93
|
-
shopStore.state.tabs[shopStore.state.currentTab]['validating']=true
|
|
94
|
-
//validate step, like send forms or something like this
|
|
95
|
-
Promise.resolve(obj.nextfunction()).then((resp)=>{
|
|
96
|
-
if (resp){
|
|
97
|
-
shopStore.state.tabs[shopStore.state.currentTab]['valid']=true
|
|
98
|
-
shopStore.state.tabs[shopStore.state.currentTab]['validating']=false
|
|
99
|
-
useTimeoutFn(() => {
|
|
100
|
-
shopStore.navigateToNext()
|
|
101
|
-
}, 300)
|
|
102
|
-
|
|
103
|
-
}else{
|
|
104
|
-
shopStore.state.tabs[shopStore.state.currentTab]['valid']=false
|
|
105
|
-
shopStore.state.tabs[shopStore.state.currentTab]['validating']=false
|
|
106
|
-
}
|
|
107
|
-
}).catch(error=>{
|
|
108
|
-
shopStore.state.tabs[shopStore.state.currentTab]['valid']=false
|
|
109
|
-
shopStore.state.tabs[shopStore.state.currentTab]['validating']=false
|
|
110
|
-
})
|
|
111
|
-
console.log("----")
|
|
92
|
+
shopStore.tabValidation(obj.nextfunction, shopStore.navigateToNext)
|
|
112
93
|
}
|
|
113
94
|
|
|
114
95
|
function active(obj){
|
|
@@ -141,7 +122,6 @@ sl-tap-panel {
|
|
|
141
122
|
.viur-shop-stepper-bar {
|
|
142
123
|
margin-top: var(--shop-leaf-gap, var(--ignt-spacing-small));
|
|
143
124
|
justify-self: flex-end;
|
|
144
|
-
margin-top: auto;
|
|
145
125
|
}
|
|
146
126
|
|
|
147
127
|
.hint{
|
|
@@ -154,7 +134,7 @@ sl-tap-panel {
|
|
|
154
134
|
height: auto;
|
|
155
135
|
min-height: var(--sl-input-height-large);
|
|
156
136
|
font-size: var(--sl-button-font-size-large);
|
|
157
|
-
line-height: calc(var(--sl-input-height-large) - var(--sl-input-border-width)* 2);
|
|
137
|
+
line-height: calc(var(--sl-input-height-large) - var(--sl-input-border-width) * 2);
|
|
158
138
|
}
|
|
159
139
|
.action-button-hint::part(base){
|
|
160
140
|
border-top-left-radius: 0;
|
package/src/ShopSummary.vue
CHANGED
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
shopStore.state.order?.cart?.dest?.shipping?.dest?.delivery_time_range ?
|
|
56
56
|
shopStore.state.order?.cart?.dest?.shipping?.dest?.delivery_time_range :
|
|
57
57
|
0
|
|
58
|
-
}} {{
|
|
58
|
+
}} {{ $t('viur.shop.day',state.shippingTime) }}
|
|
59
59
|
</span>
|
|
60
60
|
</div>
|
|
61
61
|
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
</div>
|
|
66
66
|
</slot>
|
|
67
67
|
</LoadingHandler>
|
|
68
|
+
|
|
68
69
|
</template>
|
|
69
70
|
|
|
70
71
|
<script setup>
|
|
@@ -103,6 +104,14 @@ const state = reactive({
|
|
|
103
104
|
|
|
104
105
|
return total
|
|
105
106
|
}),
|
|
107
|
+
shippingTime:computed(()=>{
|
|
108
|
+
try{
|
|
109
|
+
let times = shopStore.state.order?.cart?.dest?.shipping?.dest?.delivery_time_range.split(" - ").map(x=>parseInt(x))
|
|
110
|
+
return times[1] - times[0]
|
|
111
|
+
}catch(e){
|
|
112
|
+
return "-"
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
106
115
|
discount:computed(()=> (state.cartTotal - shopStore.state.cartRoot.total_discount_price)*-1),
|
|
107
116
|
total: computed(() => {
|
|
108
117
|
return shopStore.state.cartRoot.total
|
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
>
|
|
15
15
|
<template v-slot="{option, index}">
|
|
16
16
|
<!--<img slot="image">-->
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
<sl-bar class="shipping-bar">
|
|
18
|
+
<div slot="left">
|
|
19
|
+
<sl-format-number lang="de" type="currency" currency="EUR" :value=" option['dest']['shipping_cost']" v-if="option['dest']['shipping_cost']">
|
|
20
|
+
</sl-format-number>
|
|
21
|
+
<span v-else>{{ $t('viur.shop.free_shipping') }}</span>
|
|
22
|
+
</div>
|
|
23
|
+
<span slot="right">{{$t('viur.shop.deliverytime')}}: {{ option['dest']['delivery_time_range'] }} {{ $t('viur.shop.day',option['dest']['delivery_time_max'] - option['dest']['delivery_time_min']) }}</span>
|
|
24
|
+
</sl-bar>
|
|
25
|
+
<!--{{ option['dest']['name'] }}-->
|
|
22
26
|
</template>
|
|
23
27
|
</card-selector>
|
|
24
28
|
</loading-handler>
|
|
@@ -66,7 +70,7 @@ function updateShippingMethod(selection){
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
async function nextStep(){
|
|
69
|
-
await fetchOrder(shopStore.state.orderKey)
|
|
73
|
+
return await fetchOrder(shopStore.state.orderKey)
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
onBeforeMount(()=>{
|
|
@@ -77,5 +81,6 @@ onBeforeMount(()=>{
|
|
|
77
81
|
|
|
78
82
|
|
|
79
83
|
<style scoped>
|
|
84
|
+
.shipping-bar {width: 100%; margin-right: var(--ignt-spacing-large)}
|
|
80
85
|
|
|
81
86
|
</style>
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
:value="item.quantity"
|
|
28
28
|
@sl-change="changeAmount($event.target.value)"
|
|
29
29
|
>
|
|
30
|
-
<dialog-Button slot="prefix" class="decent" v-if="item.quantity===1" variant="danger" outline>
|
|
30
|
+
<dialog-Button slot="prefix" class="decent" v-if="item.quantity===1" variant="danger" outline :disabled="!edit">
|
|
31
31
|
<sl-icon name="trash"></sl-icon>
|
|
32
32
|
<template #dialog="{close}">
|
|
33
33
|
{{ $t('messages.remove_article_from_cart') }}
|
|
@@ -122,16 +122,14 @@ function initUnzerForm(){
|
|
|
122
122
|
function paymentError(error){
|
|
123
123
|
state.loading = false
|
|
124
124
|
state.hasError = true
|
|
125
|
-
//reset session id
|
|
126
|
-
//state.paymentHandler[shopStore.state.order?.['payment_provider']].jsessionId = state.paymentHandler[shopStore.state.order?.['payment_provider']].requestJSessionId()
|
|
127
125
|
}
|
|
128
126
|
|
|
129
127
|
|
|
130
128
|
function submitFormToUnzer(){
|
|
131
129
|
PaymentCheckPause()
|
|
132
130
|
state.loading = true
|
|
131
|
+
state.hasError = false
|
|
133
132
|
let paymenttarget = shopStore.state.order?.['payment_provider'].split("-")[1]
|
|
134
|
-
console.log(state.paymentHandler)
|
|
135
133
|
//send to unzer
|
|
136
134
|
state.paymentHandler[shopStore.state.order?.['payment_provider']].createResource().then((result)=>{
|
|
137
135
|
Request.post(`${shopStore.state.shopUrl}/pp_unzer_${paymenttarget}/save_type`, {dataObj:{
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
slot="nav"
|
|
5
5
|
:panel="tab"
|
|
6
6
|
:disabled="!shopStore.state.tabs[tab]['active']"
|
|
7
|
-
@click="
|
|
7
|
+
@click="navigate"
|
|
8
8
|
>
|
|
9
9
|
<div class="viur-shop-order-step">
|
|
10
10
|
<sl-icon
|
|
@@ -49,6 +49,12 @@ const props = defineProps({
|
|
|
49
49
|
default:"-"
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
|
+
|
|
53
|
+
function navigate(){
|
|
54
|
+
if (!shopStore.state.tabs[props.tab]['active']) return false
|
|
55
|
+
shopStore.navigateToTab(props.tab)
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
</script>
|
|
53
59
|
|
|
54
60
|
<style scoped>
|
|
@@ -1,98 +1,119 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const shopStore = useViurShopStore()
|
|
1
|
+
import {defineStore} from 'pinia';
|
|
2
|
+
import {computed, reactive, ref} from 'vue';
|
|
3
|
+
import {useCart} from '../composables/cart';
|
|
4
|
+
import {useOrder} from '../composables/order';
|
|
5
|
+
import {useViurShopStore} from '../shop';
|
|
6
|
+
import {useShipping} from './shipping.js';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// for shipping and both mode
|
|
13
|
-
shippingIsLoading:computed(()=>{
|
|
14
|
-
if (!state.shippingForm){
|
|
15
|
-
return true
|
|
16
|
-
}
|
|
17
|
-
return state.shippingForm.state.loading
|
|
18
|
-
}),
|
|
19
|
-
shippingIsUpdating:false, // for shipping and both mode
|
|
20
|
-
shippingData:{},
|
|
21
|
-
shippingValid:computed(()=>{
|
|
22
|
-
if(shopStore.state.cartRoot?.['shipping_address']){
|
|
23
|
-
return true
|
|
24
|
-
}
|
|
25
|
-
return false
|
|
26
|
-
}),
|
|
8
|
+
export const useAddress = defineStore('useAddressStore', () => {
|
|
9
|
+
const shopStore = useViurShopStore();
|
|
10
|
+
const {fetchShippingData} = useShipping();
|
|
27
11
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
12
|
+
const state = reactive({
|
|
13
|
+
billingIsShipping: true,
|
|
14
|
+
shippingForm: ref(null),
|
|
15
|
+
// for shipping and both mode
|
|
16
|
+
shippingIsLoading: computed(() => {
|
|
17
|
+
if (!state.shippingForm) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return state.shippingForm.state.loading;
|
|
21
|
+
}),
|
|
22
|
+
shippingIsUpdating: false, // for shipping and both mode
|
|
23
|
+
shippingData: {},
|
|
24
|
+
shippingValid: computed(() => {
|
|
25
|
+
if (shopStore.state.cartRoot?.['shipping_address']) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}),
|
|
43
30
|
|
|
44
|
-
|
|
31
|
+
billingForm: ref(null),
|
|
32
|
+
billingIsLoading: computed(() => {
|
|
33
|
+
if (!state.billingForm) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return state.billingForm.state.loading;
|
|
37
|
+
}),
|
|
38
|
+
billingIsUpdating: false,
|
|
39
|
+
billingData: {},
|
|
40
|
+
billingValid: computed(() => {
|
|
41
|
+
if (shopStore.state.order?.['billing_address']) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}),
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
state[`${type}IsUpdating`] = true
|
|
48
|
-
return state[`${type}Form`].sendData().then(async (resp)=>{
|
|
49
|
-
let data = await resp.json()
|
|
47
|
+
});
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
state[`${type}IsUpdating`] = undefined
|
|
56
|
-
return data
|
|
57
|
-
}).catch(error=>{
|
|
58
|
-
state[`${type}Form`].state.loading = false
|
|
59
|
-
return {'action':"error"}
|
|
60
|
-
})
|
|
61
|
-
}
|
|
49
|
+
function saveForm(type, billingIsShipping = false) {
|
|
50
|
+
state[`${type}IsUpdating`] = true;
|
|
51
|
+
return state[`${type}Form`].sendData().then(async (resp) => {
|
|
52
|
+
let data = await resp.json();
|
|
62
53
|
|
|
63
|
-
|
|
54
|
+
if (['addSuccess', 'editSuccess'].includes(data['action'])) {
|
|
64
55
|
if (billingIsShipping) {
|
|
65
|
-
|
|
66
|
-
}else{
|
|
67
|
-
|
|
68
|
-
saveForm('shipping').then(()=>{
|
|
69
|
-
saveForm('billing').then(()=>{
|
|
70
|
-
resolve({'action':'editSuccess'})
|
|
71
|
-
}).catch((e)=>reject(e))
|
|
72
|
-
}).catch((e)=>reject(e))
|
|
73
|
-
})
|
|
56
|
+
state.billingData = state.shippingData = data['values'];
|
|
57
|
+
} else {
|
|
58
|
+
state[`${type}Data`] = data['values'];
|
|
74
59
|
}
|
|
75
|
-
|
|
60
|
+
await updateAddresses(type, billingIsShipping);
|
|
61
|
+
}
|
|
62
|
+
state[`${type}IsUpdating`] = undefined;
|
|
63
|
+
return data;
|
|
64
|
+
}).catch(error => {
|
|
65
|
+
state[`${type}Form`].state.loading = false;
|
|
66
|
+
return {'action': 'error'};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
70
|
+
function saveAddresses(billingIsShipping = false) {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
if (billingIsShipping) {
|
|
73
|
+
saveForm('billing', billingIsShipping)
|
|
74
|
+
.then(async res => {
|
|
75
|
+
await fetchShippingData(); // different address --> other shipping
|
|
76
|
+
resolve(res);
|
|
77
|
+
})
|
|
78
|
+
.catch(reject);
|
|
79
|
+
} else {
|
|
80
|
+
saveForm('shipping').then(() => {
|
|
81
|
+
saveForm('billing').then(async () => {
|
|
82
|
+
await fetchShippingData(); // different address --> other shipping
|
|
83
|
+
resolve({'action': 'editSuccess'});
|
|
84
|
+
}).catch((e) => reject(e));
|
|
85
|
+
}).catch((e) => reject(e));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
async function updateAddresses(type, billingIsShipping = false) {
|
|
91
|
+
let key = state[`${type}Data`]['key'];
|
|
92
|
+
if (type === 'shipping') {
|
|
93
|
+
const {updateCart, fetchCart, shippingAddressKey} = useCart();
|
|
94
|
+
if (key === shippingAddressKey.value) {
|
|
95
|
+
// The address skel is the same, we just need to reload the relation
|
|
96
|
+
fetchCart();
|
|
97
|
+
} else {
|
|
98
|
+
await updateCart({shipping_address_key: key});
|
|
99
|
+
}
|
|
100
|
+
} else if (type === 'billing') {
|
|
101
|
+
const {addOrUpdateOrder, fetchOrder, billingAddressKey} = useOrder();
|
|
102
|
+
if (key === billingAddressKey.value) { // The address skel is the same, we just need to reload the relation
|
|
103
|
+
fetchOrder(shopStore.state.orderKey);
|
|
104
|
+
} else {
|
|
105
|
+
await addOrUpdateOrder({billing_address_key: key});
|
|
106
|
+
}
|
|
107
|
+
if (billingIsShipping) {
|
|
108
|
+
await updateAddresses('shipping', false);
|
|
109
|
+
}
|
|
97
110
|
}
|
|
98
|
-
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
state,
|
|
115
|
+
saveForm,
|
|
116
|
+
updateAddresses,
|
|
117
|
+
saveAddresses,
|
|
118
|
+
};
|
|
119
|
+
});
|
package/src/composables/cart.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {reactive} from 'vue'
|
|
1
|
+
import {computed, reactive} from 'vue';
|
|
2
2
|
import {Request} from '@viur/vue-utils'
|
|
3
3
|
import { removeUndefinedValues} from '../utils'
|
|
4
4
|
|
|
@@ -61,8 +61,9 @@ export function useCart() {
|
|
|
61
61
|
// fetch list of Rootnodes and saves the first one
|
|
62
62
|
|
|
63
63
|
return Request.get(`${shopStore.state.shopUrl}/cart/listRootNodes`).then(async (resp)=>{
|
|
64
|
-
let data = await resp.json()
|
|
64
|
+
let data = await resp.clone().json()
|
|
65
65
|
shopStore.state.cartRoot = data.filter(i=>i['cart_type']==='basket')?.[0] ? data.filter(i=>i['cart_type']==='basket')[0]:[]
|
|
66
|
+
return resp
|
|
66
67
|
})
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -71,8 +72,9 @@ export function useCart() {
|
|
|
71
72
|
return Request.get(`${shopStore.state.shopApiUrl}/cart_list`,{dataObj:{
|
|
72
73
|
cart_key:key
|
|
73
74
|
}}).then(async( resp) =>{
|
|
74
|
-
let data = await resp.json()
|
|
75
|
+
let data = await resp.clone().json()
|
|
75
76
|
shopStore.state.cartList=data
|
|
77
|
+
return resp
|
|
76
78
|
})
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -91,7 +93,7 @@ export function useCart() {
|
|
|
91
93
|
cart_type:cart_type?cart_type:shopStore.state.cartRoot['cart_type'],
|
|
92
94
|
name:name?name:shopStore.state.cartRoot['name'],
|
|
93
95
|
customer_comment:customer_comment?customer_comment:shopStore.state.cartRoot['customer_comment'],
|
|
94
|
-
shipping_address_key:shipping_address_key?shipping_address_key:
|
|
96
|
+
shipping_address_key:shipping_address_key?shipping_address_key:shippingAddressKey.value,
|
|
95
97
|
shipping_key:shipping_key?shipping_key:shopStore.state.cartRoot?.['shipping']?.['dest']?.['key'],
|
|
96
98
|
discount_key:discount_key?discount_key:shopStore.state.cartRoot?.['discount']?.['dest']?.['key'],
|
|
97
99
|
cart_key:cart_key ? cart_key : shopStore.state.cartRoot['key'],
|
|
@@ -105,6 +107,7 @@ export function useCart() {
|
|
|
105
107
|
dataObj: removeUndefinedValues(data)
|
|
106
108
|
}).then(async (resp)=>{
|
|
107
109
|
fetchCart()
|
|
110
|
+
return resp
|
|
108
111
|
})
|
|
109
112
|
}
|
|
110
113
|
|
|
@@ -171,7 +174,7 @@ export function useCart() {
|
|
|
171
174
|
});
|
|
172
175
|
}
|
|
173
176
|
|
|
174
|
-
|
|
177
|
+
const shippingAddressKey = computed(() => shopStore.state.cartRoot?.['shipping_address']?.['dest']?.['key']);
|
|
175
178
|
|
|
176
179
|
return {
|
|
177
180
|
state,
|
|
@@ -184,6 +187,7 @@ export function useCart() {
|
|
|
184
187
|
createCart,
|
|
185
188
|
getValue,
|
|
186
189
|
addDiscount,
|
|
187
|
-
removeDiscount
|
|
190
|
+
removeDiscount,
|
|
191
|
+
shippingAddressKey,
|
|
188
192
|
}
|
|
189
193
|
}
|
package/src/composables/order.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import {Request} from '@viur/vue-utils';
|
|
2
|
+
import {useUrlSearchParams} from '@vueuse/core';
|
|
3
|
+
import {computed, reactive} from 'vue';
|
|
4
|
+
import {useViurShopStore} from '../shop';
|
|
5
|
+
import {removeUndefinedValues} from '../utils';
|
|
6
6
|
|
|
7
7
|
export function useOrder() {
|
|
8
8
|
const state = reactive({
|
|
@@ -20,14 +20,16 @@ export function useOrder() {
|
|
|
20
20
|
}
|
|
21
21
|
function fetchOrder(key){
|
|
22
22
|
state.isLoading = true
|
|
23
|
+
|
|
23
24
|
return Request.post(shopStore.state.shopApiUrl+"/order_view",{dataObj:{
|
|
24
25
|
"order_key": key
|
|
25
26
|
}}).then(async (resp)=>{
|
|
26
|
-
let data = await resp.json()
|
|
27
|
+
let data = await resp.clone().json()
|
|
27
28
|
updateOrderState(data['skel']['key'], data['skel'])
|
|
28
29
|
shopStore.state.canCheckout = data["can_checkout"]
|
|
29
30
|
shopStore.state.canOrder = data["can_order"]
|
|
30
31
|
state.isLoading = false
|
|
32
|
+
return resp
|
|
31
33
|
}).catch((error)=>{
|
|
32
34
|
shopStore.state.order = null
|
|
33
35
|
shopStore.state.orderKey = null
|
|
@@ -49,7 +51,7 @@ export function useOrder() {
|
|
|
49
51
|
let url = shopStore.state.shopApiUrl+"/order_add"
|
|
50
52
|
let data = {
|
|
51
53
|
payment_provider:payment_provider?payment_provider:shopStore.state.order?.['payment_provider'],
|
|
52
|
-
billing_address_key:billing_address_key?billing_address_key:
|
|
54
|
+
billing_address_key:billing_address_key?billing_address_key:billingAddressKey.value,
|
|
53
55
|
customer_key:customer_key?customer_key:shopStore.state.order?.['customer_key']?.['dest']?.['key'],
|
|
54
56
|
state_ordered:state_ordered?state_ordered:shopStore.state.order?.['state_ordered'],
|
|
55
57
|
state_paid:state_paid?state_paid:shopStore.state.order?.['state_paid'],
|
|
@@ -64,19 +66,22 @@ export function useOrder() {
|
|
|
64
66
|
data["cart_key"] = shopStore.state.cartRoot['key']
|
|
65
67
|
}
|
|
66
68
|
return Request.post(url,{dataObj:removeUndefinedValues(data)}).then(async(resp)=>{
|
|
67
|
-
let data = await resp.json()
|
|
69
|
+
let data = await resp.clone().json()
|
|
68
70
|
updateOrderState(data['key'], data)
|
|
69
71
|
state.isUpdating=false
|
|
72
|
+
return resp
|
|
70
73
|
}).then(async ( resp)=>{
|
|
71
74
|
fetchOrder(shopStore.state.orderKey)
|
|
72
75
|
return resp
|
|
73
76
|
})
|
|
74
77
|
}
|
|
75
78
|
|
|
79
|
+
const billingAddressKey = computed(() => shopStore.state.order?.['billing_address']?.['dest']?.['key']);
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
return {
|
|
82
|
+
state,
|
|
83
|
+
fetchOrder,
|
|
84
|
+
addOrUpdateOrder,
|
|
85
|
+
billingAddressKey,
|
|
86
|
+
};
|
|
82
87
|
}
|
|
@@ -16,6 +16,7 @@ export const usePayment = defineStore("usePaymentStore", () => {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const simpleProviders = [
|
|
19
|
+
"invoice",
|
|
19
20
|
'prepayment',
|
|
20
21
|
'unzer-paypal',
|
|
21
22
|
'unzer-sofort'
|
|
@@ -46,7 +47,7 @@ export const usePayment = defineStore("usePaymentStore", () => {
|
|
|
46
47
|
currentOption.description = provider[1]['descr']
|
|
47
48
|
currentOption.icon = iconMap[provider[0]]
|
|
48
49
|
currentOption.widget = "simple"
|
|
49
|
-
|
|
50
|
+
//if (simpleProviders.includes(provider[0])){
|
|
50
51
|
// currentOption.widget = "simple" // payment provider musst be initialized later
|
|
51
52
|
//}
|
|
52
53
|
|
|
@@ -72,4 +73,4 @@ export const usePayment = defineStore("usePaymentStore", () => {
|
|
|
72
73
|
fetchPaymentData
|
|
73
74
|
|
|
74
75
|
}
|
|
75
|
-
})
|
|
76
|
+
})
|
|
@@ -1,40 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import {Request} from '@viur/vue-utils';
|
|
2
|
+
import {defineStore} from 'pinia';
|
|
3
|
+
import {reactive} from 'vue';
|
|
4
|
+
import {useI18n} from 'vue-i18n';
|
|
5
|
+
import {useViurShopStore} from '../shop';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Store that holds available shipping options
|
|
9
|
+
*/
|
|
10
|
+
export const useShipping = defineStore('useShippingStore', () => {
|
|
11
|
+
const i18n = useI18n();
|
|
12
|
+
const shopStore = useViurShopStore();
|
|
13
|
+
const defaultErrorMessage = i18n.t('viur.shop.error_message');
|
|
14
|
+
const state = reactive({
|
|
15
|
+
isLoading: false,
|
|
16
|
+
isUpdating: false,
|
|
17
|
+
hasError: false,
|
|
18
|
+
errorMessage: defaultErrorMessage,
|
|
19
|
+
shippingData: [],
|
|
20
|
+
});
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
/**
|
|
23
|
+
* fetch available shipping options from API
|
|
24
|
+
*/
|
|
25
|
+
function fetchShippingData() {
|
|
26
|
+
state.isLoading = true;
|
|
27
|
+
return Request.get(`${shopStore.state.shopApiUrl}/shipping_list`, {
|
|
28
|
+
dataObj: {
|
|
29
|
+
cart_key: shopStore.state.cartRoot['key'],
|
|
30
|
+
},
|
|
31
|
+
}).then(async (resp) => {
|
|
32
|
+
state.shippingData = await resp.json();
|
|
33
|
+
if (state.shippingData.length === 0) {
|
|
34
|
+
state.hasError = true;
|
|
35
|
+
state.errorMessage = i18n.t('shop.no_valid_shipping_found');
|
|
36
|
+
}
|
|
37
|
+
state.isLoading = false;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
33
40
|
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
42
|
+
return {
|
|
43
|
+
state,
|
|
44
|
+
fetchShippingData,
|
|
45
|
+
};
|
|
46
|
+
});
|
package/src/shop.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { reactive, computed, watch, shallowRef } from "vue";
|
|
3
3
|
import {ShopCart, ShopUserDataGuest, ShopShippingMethod, ShopPaymentProvider, ShopOrderComplete, ShopOrderConfirm} from './Steps/index'
|
|
4
4
|
import { defineStore } from "pinia";
|
|
5
|
-
import { useUrlSearchParams } from '@vueuse/core'
|
|
5
|
+
import { useUrlSearchParams,useTimeoutFn } from '@vueuse/core'
|
|
6
6
|
import AddressFormLayout from './components/AddressFormLayout.vue';
|
|
7
7
|
|
|
8
8
|
import { Request } from "@viur/vue-utils";
|
|
@@ -38,7 +38,7 @@ export const useViurShopStore = defineStore("viurshopStore", () => {
|
|
|
38
38
|
params:{},
|
|
39
39
|
displayName: "viur.shop.order_step_data", //Daten Eingeben
|
|
40
40
|
icon: { name: "card-list" },
|
|
41
|
-
active:computed(()
|
|
41
|
+
active:computed(()=>state.order && !state.order?.['is_checkout_in_progress'] && !state.order?.['is_ordered'] && state.cartList.length>0), //active if checkout not startet and cart is not empty
|
|
42
42
|
validating:false,
|
|
43
43
|
valid:false
|
|
44
44
|
},
|
|
@@ -56,7 +56,7 @@ export const useViurShopStore = defineStore("viurshopStore", () => {
|
|
|
56
56
|
params:{},
|
|
57
57
|
displayName: "viur.shop.order_step_payment", //Zahlungsart auswählen
|
|
58
58
|
icon: { name: "credit-card" },
|
|
59
|
-
active:computed(()=>!state.order?.['is_checkout_in_progress'] && state.order && state.cartRoot?.['shipping']), // we need a active order
|
|
59
|
+
active:computed(()=>!state.order?.['is_checkout_in_progress'] && state.order && state.cartRoot?.['shipping'] && state.cartRoot?.['shipping_address']), // we need a active order
|
|
60
60
|
validating:false,
|
|
61
61
|
valid:false
|
|
62
62
|
},
|
|
@@ -199,7 +199,7 @@ export const useViurShopStore = defineStore("viurshopStore", () => {
|
|
|
199
199
|
Request.post(`${state.shopUrl}/order/checkout_start`,{dataObj:{
|
|
200
200
|
order_key:state.orderKey
|
|
201
201
|
}}).then(async (resp)=>{
|
|
202
|
-
let data = await resp.json()
|
|
202
|
+
let data = await resp.clone().json()
|
|
203
203
|
state.paymentProviderData = data['payment']
|
|
204
204
|
|
|
205
205
|
if (!data['payment']){
|
|
@@ -212,6 +212,7 @@ export const useViurShopStore = defineStore("viurshopStore", () => {
|
|
|
212
212
|
}else{
|
|
213
213
|
resolve()
|
|
214
214
|
}
|
|
215
|
+
return resp
|
|
215
216
|
}).catch(error=>{
|
|
216
217
|
reject(error)
|
|
217
218
|
})
|
|
@@ -224,28 +225,53 @@ export const useViurShopStore = defineStore("viurshopStore", () => {
|
|
|
224
225
|
Request.post(`${state.shopUrl}/order/checkout_order`,{dataObj:{
|
|
225
226
|
order_key:state.orderKey
|
|
226
227
|
}}).then(async (resp)=>{
|
|
227
|
-
let data = await resp.json()
|
|
228
|
+
let data = await resp.clone().json()
|
|
228
229
|
if (!resp.ok){
|
|
229
230
|
reject(data)
|
|
230
231
|
} else {
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
state.order = data['skel']
|
|
233
|
+
state.paymentProviderData = data['payment']
|
|
233
234
|
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
if(state.order?.['is_ordered']){
|
|
236
|
+
// order is finished
|
|
237
|
+
useTimeoutFn(() => {
|
|
236
238
|
navigateToTab('complete')
|
|
237
|
-
|
|
238
|
-
resolve(data)
|
|
239
|
-
}
|
|
240
|
-
|
|
239
|
+
}, 300)
|
|
241
240
|
|
|
241
|
+
}
|
|
242
|
+
resolve(data)
|
|
243
|
+
}
|
|
244
|
+
return resp
|
|
242
245
|
}).catch(error=>{
|
|
243
246
|
reject(error)
|
|
244
247
|
})
|
|
245
248
|
})
|
|
246
249
|
}
|
|
247
250
|
|
|
251
|
+
function tabValidation(nextfunction, navigatefunction){
|
|
252
|
+
state.tabs[state.currentTab]['valid']=false
|
|
253
|
+
state.tabs[state.currentTab]['validating']=true
|
|
254
|
+
|
|
255
|
+
//validate step, like send forms or something like this
|
|
256
|
+
Promise.resolve(nextfunction()).then((resp)=>{
|
|
248
257
|
|
|
258
|
+
if (resp){
|
|
259
|
+
state.tabs[state.currentTab]['valid']=true
|
|
260
|
+
state.tabs[state.currentTab]['validating']=false
|
|
261
|
+
useTimeoutFn(() => {
|
|
262
|
+
navigatefunction()
|
|
263
|
+
}, 300)
|
|
264
|
+
|
|
265
|
+
}else{
|
|
266
|
+
state.tabs[state.currentTab]['valid']=false
|
|
267
|
+
state.tabs[state.currentTab]['validating']=false
|
|
268
|
+
}
|
|
269
|
+
}).catch(error=>{
|
|
270
|
+
console.log(error)
|
|
271
|
+
state.tabs[state.currentTab]['valid']=false
|
|
272
|
+
state.tabs[state.currentTab]['validating']=false
|
|
273
|
+
})
|
|
274
|
+
}
|
|
249
275
|
|
|
250
276
|
|
|
251
277
|
return {
|
|
@@ -253,6 +279,7 @@ export const useViurShopStore = defineStore("viurshopStore", () => {
|
|
|
253
279
|
navigateToTab,
|
|
254
280
|
navigateToNext,
|
|
255
281
|
navigateToPrevious,
|
|
282
|
+
tabValidation,
|
|
256
283
|
fetchMetaData,
|
|
257
284
|
checkout,
|
|
258
285
|
checkoutOrder,
|