Hey everybody!
I am quite new to the platform and also to JavaScript, so please forgive any questions, which might seam obvious.
Here is my problem:
I have a database with different Hotels. Each Hotel has a name (HName), different seasons, different Meal Categories, which can be selected, different rooms etc. In the end I want to filter my DataBase according to the Hotel Name, which was selected in a Dropdown… After having filtered only this Hotel, I want to search for the desired price (according to the season, selected meal and selected room type), which is stored in one of the columns of the database.
Here is my code:
export function DropH1Name_change(event) {
H1Name = $w(’ #DropH1Name ').value;
console.log(‘Name of Hotel 1: ’ + H1Name);
}
function searchHotelPrice (DataSet, HName, HMeal, HRoom, date) {
DataSet.setFilter(wixData.filter()
.contains(“name”, HName));
console.log(DataSet.getCurrentItem().name)
let price = 0;
if (date >= DataSet.getCurrentItem().s1_begin && date <= DataSet.getCurrentItem().s1_end){
switch (HMeal) {
case “BB”:
switch (HRoom) {
case “Single”: price = DataSet.getCurrentItem().s1BbSingle; break;
case “Double”: price = DataSet.getCurrentItem().s1BbDouble; break;
case “Triple”: price = DataSet.getCurrentItem().s1BbTriple; break;
case “Quadruple”: price = DataSet.getCurrentItem().s1BbQuadruple; break;
default: break;}
break;
case “HB”:
switch (HRoom) {
case “Single”: price = DataSet.getCurrentItem().s1HbSingle; break;
case “Double”: price = DataSet.getCurrentItem().s1HbDouble; break;
case “Triple”: price = DataSet.getCurrentItem().s1HbTriple; break;
case “Quadruple”: price = DataSet.getCurrentItem().s1HbQuadruple; break;
default: break;}
break;
case “FB”:
switch (HRoom) {
case “Single”: price = DataSet.getCurrentItem().s1FbSingle; break;
case “Double”: price = DataSet.getCurrentItem().s1FbDouble; break;
case “Triple”: price = DataSet.getCurrentItem().s1FbTriple; break;
case “Quadruple”: price = DataSet.getCurrentItem().s1FbQuadruple; break;
default: break;}
break;
case “AIC”:
switch (HRoom) {
case “Single”: price = DataSet.getCurrentItem().s1AicSingle; break;
case “Double”: price = DataSet.getCurrentItem().s1AicDouble; break;
case “Triple”: price = DataSet.getCurrentItem().s1AicTriple; break;
case “Quadruple”: price = DataSet.getCurrentItem().s1AicQuadruple; break;
default: break;}
break;
default: break;
}
} else if { //much more code, basically the same as above only for other seasons
} else if { price =0;
}
return price;
}
export function button1_click(event) {
let date = $w(’ #DatePickArrival ‘).value;
let cost = 0;
TotHotel1Cost = 0;
for (var i = 0; i < ArrHotel1Rooms.length; i++) {
cost = searchHotelPrice($w(’ #DataHotel ‘), H1Name, H1Meal, ArrHotel1Rooms[i], date);
TotHotel1Cost += cost;
}
$w(’ #text15 ').text = String(TotHotel1Cost);
}
The problem is not getting the value out of a hotel, but first of all to find the hotel. Every time I click the button it gives me the correct cost, but all the time for the same hotel, independent of what H1Name is.
For example: H1Name is “Blue Sapphire Hotel” in Season 1, H1Meal=“FB”, Room Category = “Double” (stored in Array ArrHotel1Rooms). I now, ALWAYS get the cost for e.g. “World Wonders Hotel”, in the correct season 1, with correct meals (full board), room category (double) and therefore correct price, but not for the Hotel I selected.
I have tried various approaches, one time by filtering as above, by setting a query (but this seems to give me an array as an output and no filtered database to which I could apply the code to search in the columns) and also by a “for statement” in which I tried to set the CurrentItemIndex to the dataset which has the corresponding hotel name. But none of those worked! It is actually quite frustrating as I spent hours trying to solve this problem.
Actually, the main thing, which I don´t know is, how to apply the code starting with the if{…} to my result(s) of the filter.
Any help would be greatly appreciated!! Thanks a lot!