"Enhance MyBookingsBook.vue with forced pickup product addition: auto-add pickup product when enabled; update logic for visibility, filtering, and basket handling for consistency."

This commit is contained in:
Jeppe Bundgaard
2025-11-12 15:33:58 +01:00
parent b10634e190
commit f5568f849b
2 changed files with 43 additions and 4 deletions
@@ -16,7 +16,7 @@ const saving = ref(false);
const error = ref<string | null>(null);
const booking = ref<any>(null);
const showPricesOnBookingPage = () => {
return false; // TODO: implement this once backend supports it
return SessionUser.hasAttribute('showPricesOnBookingPage');
};
// Add item form state
@@ -52,6 +52,7 @@ import PosDepartmentStepMobile2Addons
from "@/components/displays/department/pos/steps/mobile/elements/PosDepartmentStepMobile2Addons.vue";
import {getProductsCategory, setDepartment, setProductsCategory} from "@/components/shop/POSDepartmentProcess.vue";
import Swal from "sweetalert2";
import { getProducts } from "@/components/shop/Products.vue";
const customerNumber = ref<number | null>(SessionUser?.user?.customer_number.value ? parseInt(SessionUser.user.customer_number.value) : null);
const department = ref<any>(null);
@@ -78,7 +79,7 @@ const isDateTimeInput = ref(false);
const hasDepartment = computed(() => !!(department.value && (department.value as any).id));
const hasVehicle = computed(() => ((reg1.value !== '' && reg1Type.value !== null) || (reg2.value !== '' && reg2Type.value !== null)));
const hasShowPriceOnBookingPageAttribute = () => {
return false; // TODO: Actually check for the attribute on the selected department
return SessionUser.hasAttribute('showPricesOnBookingPage');
}
const setInputFocus = (id: string) => {
// Wait for the next tick to ensure the input is rendered
@@ -89,6 +90,24 @@ const setInputFocus = (id: string) => {
}
}, 0);
}
// Force add product "Inkl. Pick-Up" (ID: 40) when pickup is enabled
const forcedPickupProductId = 40;
const forcedPickupProduct = ref<PosProduct | null>(null);
const loadInclPickupProduct = async () => {
SessionUser.objects.products.get.single(forcedPickupProductId).then(product => {
forcedPickupProduct.value = product;
}).catch(e => {
console.warn('Could not load forced pickup product (ID: 40). Pickup option will be disabled.', e);
forcedPickupProduct.value = null;
});
}
onMounted(() => {
loadInclPickupProduct();
});
const onClickSelectDepartment = () => {
// Set the input to true
isDepartmentInput.value = true;
@@ -396,6 +415,13 @@ const getProductsCombined = computed(() => {
}
});
}
// If pickup is enabled, force-add the pickup product (ID: 40) to the basket preview
if (pickup.value && forcedPickupProduct.value) {
const exists = products.some(p => p.id === forcedPickupProduct.value.id);
if (!exists) {
products.push({ ...forcedPickupProduct.value, quantity: 1 });
}
}
return products;
});
@@ -629,11 +655,16 @@ const exteriorPriceLabel = computed(() => {
return `Pris: ${formatDkk(base?.price)}`;
});
const isPickupAddon = (p: any): boolean => {
const id = (p && p.id) ? p.id : null;
return id === 40;
}
// Filtered list of addons for the UI: hide the interior wash addon (has its own dedicated button)
// and hide the Safety Seal addon (redundant now)
const visibleAddons = computed(() => {
const addons = (selectedProduct.value?.addons || []) as any[];
return addons.filter(a => !a?.product?.name?.includes('Indvendig') && !isSafetySealAddon(a?.product));
return addons.filter(a => !a?.product?.name?.includes('Indvendig') && !isSafetySealAddon(a?.product) && !isPickupAddon(a?.product));
});
const completeBasket = computed({
@@ -646,7 +677,7 @@ const completeBasket = computed({
// Selected addons with quantity > 0 (excluding interior wash which is controlled by its own toggle)
const selectedAddons = (product.addons || [])
.map((a: any) => a?.product)
.filter((p: any) => p && (p.quantity || 0) > 0 && !(p?.name || '').includes('Indvendig') && !isSafetySealAddon(p)) as PosProduct[];
.filter((p: any) => p && (p.quantity || 0) > 0 && !(p?.name || '').includes('Indvendig') && !isSafetySealAddon(p) && !isPickupAddon(p)) as PosProduct[];
// Exterior/base product (default selected)
if (washExterior.value && exteriorWash) {
@@ -686,6 +717,14 @@ const completeBasket = computed({
}
}
// Auto-add the pickup product (id: 40) if enabled
if (pickup.value && forcedPickupProduct.value) {
const alreadyHasPickup = result.some(r => r.id === forcedPickupProduct.value?.id);
if (!alreadyHasPickup) {
result.push({ ...forcedPickupProduct.value, quantity: 1 });
}
}
return result;
},
set: () => {}