@shopbite-de/storefront 1.4.1 → 1.5.0
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/api-types/storeApiSchema.json +4503 -4363
- package/api-types/storeApiTypes.d.ts +73 -0
- package/app/app.vue +11 -2
- package/app/components/Checkout/DeliveryTimeSelect.vue +16 -5
- package/app/composables/useBusinessHours.ts +156 -0
- package/app/composables/useDeliveryTime.ts +34 -10
- package/app/composables/useHolidays.ts +49 -0
- package/package.json +2 -2
- package/test/nuxt/useBusinessHours.test.ts +58 -0
- package/test/nuxt/useDeliveryTime.test.ts +106 -3
- package/app/utils/businessHours.ts +0 -114
- package/app/utils/holidays.ts +0 -24
- package/app/utils/storeHours.ts +0 -8
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
export type ServiceInterval = { start: Date; end: Date };
|
|
2
|
-
|
|
3
|
-
export function isTuesday(date: Date): boolean {
|
|
4
|
-
return date.getDay() === 2;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function isSaturday(date: Date): boolean {
|
|
8
|
-
return date.getDay() === 6;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function getServiceIntervals(date: Date): Array<ServiceInterval> {
|
|
12
|
-
if (isTuesday(date)) return [];
|
|
13
|
-
|
|
14
|
-
const lunchStart = setTime(date, 11, 30);
|
|
15
|
-
const lunchEnd = setTime(date, 14, 30);
|
|
16
|
-
const dinnerStart = setTime(date, 17, 30);
|
|
17
|
-
const dinnerEnd = isSaturday(date)
|
|
18
|
-
? setTime(date, 23, 30)
|
|
19
|
-
: setTime(date, 23, 0);
|
|
20
|
-
|
|
21
|
-
if (isSaturday(date)) {
|
|
22
|
-
// Saturday: only dinner, no lunch
|
|
23
|
-
return [{ start: dinnerStart, end: dinnerEnd }];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return [
|
|
27
|
-
{ start: lunchStart, end: lunchEnd },
|
|
28
|
-
{ start: dinnerStart, end: dinnerEnd },
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function getEarliestSelectableTime(
|
|
33
|
-
currentTime: Date,
|
|
34
|
-
currentDeliveryTime: number | null,
|
|
35
|
-
): Date {
|
|
36
|
-
const earliest = new Date(currentTime);
|
|
37
|
-
earliest.setMinutes(earliest.getMinutes() + (currentDeliveryTime ?? 30));
|
|
38
|
-
earliest.setSeconds(0, 0);
|
|
39
|
-
return earliest;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function getNextOpeningTime(now: Ref<Date>): string | null {
|
|
43
|
-
const currentDate = now.value;
|
|
44
|
-
|
|
45
|
-
// Try up to 60 days ahead to find next opening (covers long holiday periods)
|
|
46
|
-
for (let i = 0; i < 60; i++) {
|
|
47
|
-
const checkDate = new Date(currentDate);
|
|
48
|
-
checkDate.setDate(checkDate.getDate() + i);
|
|
49
|
-
checkDate.setHours(12, 0, 0, 0); // Set to midday to avoid timezone issues
|
|
50
|
-
|
|
51
|
-
// Skip holidays
|
|
52
|
-
if (isClosedHoliday(checkDate)) continue;
|
|
53
|
-
|
|
54
|
-
const intervals = getServiceIntervals(checkDate);
|
|
55
|
-
if (intervals.length === 0) continue;
|
|
56
|
-
|
|
57
|
-
// For today, check if there's still an opening coming
|
|
58
|
-
if (i === 0) {
|
|
59
|
-
for (const interval of intervals) {
|
|
60
|
-
if (interval.start.getTime() > currentDate.getTime()) {
|
|
61
|
-
const hours = interval.start.getHours().toString().padStart(2, "0");
|
|
62
|
-
const minutes = interval.start
|
|
63
|
-
.getMinutes()
|
|
64
|
-
.toString()
|
|
65
|
-
.padStart(2, "0");
|
|
66
|
-
return `${hours}:${minutes} Uhr`;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
continue; // Today's openings have passed, check next days
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const nextOpen = intervals[0].start;
|
|
73
|
-
const day = nextOpen.getDate().toString().padStart(2, "0");
|
|
74
|
-
const month = (nextOpen.getMonth() + 1).toString().padStart(2, "0");
|
|
75
|
-
const dayName = [
|
|
76
|
-
"Sonntag",
|
|
77
|
-
"Montag",
|
|
78
|
-
"Dienstag",
|
|
79
|
-
"Mittwoch",
|
|
80
|
-
"Donnerstag",
|
|
81
|
-
"Freitag",
|
|
82
|
-
"Samstag",
|
|
83
|
-
][nextOpen.getDay()];
|
|
84
|
-
const hours = nextOpen.getHours().toString().padStart(2, "0");
|
|
85
|
-
const minutes = nextOpen.getMinutes().toString().padStart(2, "0");
|
|
86
|
-
|
|
87
|
-
if (i === 1) {
|
|
88
|
-
return `morgen um ${hours}:${minutes} Uhr`;
|
|
89
|
-
}
|
|
90
|
-
return `${dayName}, ${day}.${month}. um ${hours}:${minutes} Uhr`;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function findActiveInterval(
|
|
97
|
-
currentTime: Date,
|
|
98
|
-
currentDeliveryTime: number | null,
|
|
99
|
-
): ServiceInterval | null {
|
|
100
|
-
const intervals = getServiceIntervals(currentTime);
|
|
101
|
-
const earliest = getEarliestSelectableTime(
|
|
102
|
-
currentTime,
|
|
103
|
-
currentDeliveryTime ?? 30,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
if (intervals.length === 0) return null;
|
|
107
|
-
|
|
108
|
-
const current = intervals.find(
|
|
109
|
-
(interval) => earliest >= interval.start && earliest <= interval.end,
|
|
110
|
-
);
|
|
111
|
-
if (current) return current;
|
|
112
|
-
|
|
113
|
-
return intervals.find((interval) => interval.start > earliest) ?? null;
|
|
114
|
-
}
|
package/app/utils/holidays.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export function isClosedHoliday(date?: Date): boolean {
|
|
2
|
-
// Use provided date or current date
|
|
3
|
-
const checkDate = date ?? new Date();
|
|
4
|
-
// Format date as YYYY-MM-DD for comparison
|
|
5
|
-
const formattedDate = formatDateYYYYMMDD(checkDate);
|
|
6
|
-
|
|
7
|
-
// List of holidays (YYYY-MM-DD format)
|
|
8
|
-
const holidays = ["2025-12-31", "2026-01-01"];
|
|
9
|
-
|
|
10
|
-
return holidays.includes(formattedDate);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Formats a date as YYYY-MM-DD
|
|
15
|
-
* @param date The date to format
|
|
16
|
-
* @returns The formatted date string
|
|
17
|
-
*/
|
|
18
|
-
function formatDateYYYYMMDD(date: Date): string {
|
|
19
|
-
const year = date.getFullYear();
|
|
20
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
21
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
22
|
-
|
|
23
|
-
return `${year}-${month}-${day}`;
|
|
24
|
-
}
|
package/app/utils/storeHours.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// utils/storeHours.ts
|
|
2
|
-
export function isStoreOpen(date: Date = new Date()): boolean {
|
|
3
|
-
if (isClosedHoliday(date)) return false;
|
|
4
|
-
|
|
5
|
-
const intervals = getServiceIntervals(date);
|
|
6
|
-
if (intervals.length === 0) return false;
|
|
7
|
-
return intervals.some(({ start, end }) => date >= start && date <= end);
|
|
8
|
-
}
|