Add support for notes on products requiring them
If a product requires a note, prompt the user to input it before proceeding. The note is validated to ensure it's not empty and is attached to the order item during creation. This enhances functionality for handling customizable product orders.
This commit is contained in:
@@ -256,6 +256,44 @@ const setProductAddonQuantity = (productId, addonId, quantity) => {
|
||||
};
|
||||
|
||||
const addProductWithAddonsToOrder = async (product_id) => {
|
||||
// Check if the product requires a note
|
||||
const product = products.value.find((product) => product.id === product_id);
|
||||
if (product.requires_note) {
|
||||
// Show the note input
|
||||
await Swal.fire({
|
||||
title: 'Tilføj en note',
|
||||
input: 'text',
|
||||
inputLabel: 'Noten kan ses af kunden. F.eks. "Fjernelse af graffiti på venstre side"',
|
||||
inputAttributes: {
|
||||
autocapitalize: 'off'
|
||||
},
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Tilføj',
|
||||
showLoaderOnConfirm: true,
|
||||
preConfirm: (note) => {
|
||||
// Check if the note is empty
|
||||
if (note === "") {
|
||||
Swal.showValidationMessage(
|
||||
'Du skal tilføje en note'
|
||||
);
|
||||
} else {
|
||||
// Show the fake create order item
|
||||
showFakeCreateOrderItem(product_id, 1, 0, 0, note);
|
||||
// Create the order item
|
||||
createOrderItem(getOrderId(), product_id, 1, 0, note).then(async (result) => {
|
||||
let order_item_id = result.data.data.id;
|
||||
// Add the addons to the order
|
||||
await addAddonsToOrderMiddleware(product_id, 1, order_item_id).then(() => {
|
||||
loadOrderItems();
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
allowOutsideClick: () => !Swal.isLoading()
|
||||
});
|
||||
return;
|
||||
}
|
||||
// If the product requires a note, show the note input
|
||||
console.log(product_id);
|
||||
let quantity = 1;
|
||||
// Show the fake create order item
|
||||
|
||||
Reference in New Issue
Block a user