@viur/shop-components 0.2.0 → 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/ShopOrderStepper.vue +1 -2
- package/src/Steps/ShopShippingMethod.vue +10 -5
- package/src/composables/address.js +108 -87
- package/src/composables/cart.js +5 -4
- package/src/composables/order.js +13 -11
- package/src/composables/shipping.js +42 -36
package/package.json
CHANGED
package/src/ShopOrderStepper.vue
CHANGED
|
@@ -122,7 +122,6 @@ sl-tap-panel {
|
|
|
122
122
|
.viur-shop-stepper-bar {
|
|
123
123
|
margin-top: var(--shop-leaf-gap, var(--ignt-spacing-small));
|
|
124
124
|
justify-self: flex-end;
|
|
125
|
-
margin-top: auto;
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
.hint{
|
|
@@ -135,7 +134,7 @@ sl-tap-panel {
|
|
|
135
134
|
height: auto;
|
|
136
135
|
min-height: var(--sl-input-height-large);
|
|
137
136
|
font-size: var(--sl-button-font-size-large);
|
|
138
|
-
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);
|
|
139
138
|
}
|
|
140
139
|
.action-button-hint::part(base){
|
|
141
140
|
border-top-left-radius: 0;
|
|
@@ -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>
|
|
@@ -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>
|
|
@@ -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
|
|
|
@@ -93,7 +93,7 @@ export function useCart() {
|
|
|
93
93
|
cart_type:cart_type?cart_type:shopStore.state.cartRoot['cart_type'],
|
|
94
94
|
name:name?name:shopStore.state.cartRoot['name'],
|
|
95
95
|
customer_comment:customer_comment?customer_comment:shopStore.state.cartRoot['customer_comment'],
|
|
96
|
-
shipping_address_key:shipping_address_key?shipping_address_key:
|
|
96
|
+
shipping_address_key:shipping_address_key?shipping_address_key:shippingAddressKey.value,
|
|
97
97
|
shipping_key:shipping_key?shipping_key:shopStore.state.cartRoot?.['shipping']?.['dest']?.['key'],
|
|
98
98
|
discount_key:discount_key?discount_key:shopStore.state.cartRoot?.['discount']?.['dest']?.['key'],
|
|
99
99
|
cart_key:cart_key ? cart_key : shopStore.state.cartRoot['key'],
|
|
@@ -174,7 +174,7 @@ export function useCart() {
|
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
const shippingAddressKey = computed(() => shopStore.state.cartRoot?.['shipping_address']?.['dest']?.['key']);
|
|
178
178
|
|
|
179
179
|
return {
|
|
180
180
|
state,
|
|
@@ -187,6 +187,7 @@ export function useCart() {
|
|
|
187
187
|
createCart,
|
|
188
188
|
getValue,
|
|
189
189
|
addDiscount,
|
|
190
|
-
removeDiscount
|
|
190
|
+
removeDiscount,
|
|
191
|
+
shippingAddressKey,
|
|
191
192
|
}
|
|
192
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({
|
|
@@ -51,7 +51,7 @@ export function useOrder() {
|
|
|
51
51
|
let url = shopStore.state.shopApiUrl+"/order_add"
|
|
52
52
|
let data = {
|
|
53
53
|
payment_provider:payment_provider?payment_provider:shopStore.state.order?.['payment_provider'],
|
|
54
|
-
billing_address_key:billing_address_key?billing_address_key:
|
|
54
|
+
billing_address_key:billing_address_key?billing_address_key:billingAddressKey.value,
|
|
55
55
|
customer_key:customer_key?customer_key:shopStore.state.order?.['customer_key']?.['dest']?.['key'],
|
|
56
56
|
state_ordered:state_ordered?state_ordered:shopStore.state.order?.['state_ordered'],
|
|
57
57
|
state_paid:state_paid?state_paid:shopStore.state.order?.['state_paid'],
|
|
@@ -76,10 +76,12 @@ export function useOrder() {
|
|
|
76
76
|
})
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
const billingAddressKey = computed(() => shopStore.state.order?.['billing_address']?.['dest']?.['key']);
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
return {
|
|
82
|
+
state,
|
|
83
|
+
fetchOrder,
|
|
84
|
+
addOrUpdateOrder,
|
|
85
|
+
billingAddressKey,
|
|
86
|
+
};
|
|
85
87
|
}
|
|
@@ -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
|
+
});
|