-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStepsStore.js
More file actions
57 lines (54 loc) · 1.56 KB
/
StepsStore.js
File metadata and controls
57 lines (54 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { defineStore } from 'pinia';
import useCartStore from '@/stores/CartStore';
import functionExtension from '@/extensions/functionExtension';
export default defineStore('stepsStore', {
state: () => ({
yourDetailsActive: true,
shippingActive: false,
paymentActive: false,
}),
actions: {
setData(data) {
this.$patch(data);
},
setInitialStepState() {
const { name } = this.$router.currentRoute.value;
this.setData({
yourDetailsActive: name === 'DetailsPage' || name === 'ShippingPage' || name === 'PaymentPage',
shippingActive: name === 'ShippingPage' || name === 'PaymentPage',
paymentActive: name === 'PaymentPage',
});
},
goToYouDetails() {
this.setData({
yourDetailsActive: true,
shippingActive: false,
paymentActive: false,
});
this.$router.push('/');
},
async goToShipping() {
// If all products within the cart do not require shipping then whenever this is called go directly to payment.
const { cart } = useCartStore();
await functionExtension('onSetShippingStep');
if (!cart.is_virtual) {
this.setData({
yourDetailsActive: true,
shippingActive: true,
paymentActive: false,
});
this.$router.push('/shipping');
} else {
this.goToPayment();
}
},
goToPayment() {
this.setData({
yourDetailsActive: true,
shippingActive: true,
paymentActive: true,
});
this.$router.push('/payments');
},
},
});