Hello,
I created a Code to check the Input field values of my customers for the return of my product. Basically, I ask them to Input the OrderNumber and their Email and compare it with the Database values from Stores → Orders.
If the Email and the OrderNumber is correct, then I want the customer to be let to another page after the click of send button. And the Input field values should be saved into another database. Otherwise, they should get an error message.
Unfortunately nothing happens, when I click on send.
This is my Code:
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
// Event handler for the click on the "Send" button
$w('#sendButton').onClick(() => {
// Retrieve user inputs
const orderNumber = $w('#orderNumberInput').value;
const emailAddress = $w('#emailInput').value;
// Database query for the order number
wixData.query('Stores/Orders')
.eq('number', orderNumber)
.find()
.then((results) => {
if (results.items.length > 0) {
// Check if the entered email address is in the same row
const order = results.items[0];
if (order.buyerInfo === emailAddress) {
// Email address and order number match
// Extract the content from the "totals" column
const orderTotals = order.totals;
// Save input data to the "Retoure" database
wixData.insert('Retoure', { orderNumber, emailAddress, totals: orderTotals })
.then(() => {
// Open the page "www.zodis.de/retoure-adresse"
wixLocation.to('http://www.abc.de/retoure-adresse');
})
.catch((error) => {
// Error when saving to the "Retoure" database
console.error('Error when saving to the "Retoure" database:', error);
});
} else {
// Error: Email address does not belong to the order number
showErrorMessage('The entered email address does not belong to the specified order number.');
}
} else {
// Error: Order number not found
showErrorMessage('Order number not found.');
}
})
.catch((error) => {
// Error in the database query
console.error('Error in the database query:', error);
});
});
// Function to display an error message on the page
function showErrorMessage(message) {
// Display the element on the page (e.g., a text element with the ID "errorMessage")
$w('#errorMessage').text = message;
$w('#errorMessage').show();
}
});
Thanks for the support
BR Albert