Add filter for "bio"/organic

This commit is contained in:
Simeon Macke (01505675) 2023-05-24 17:16:57 +02:00
parent a52ca5c51a
commit 72f913ea76
2 changed files with 11 additions and 5 deletions

View File

@ -38,7 +38,8 @@ function sparToCanonical(rawItems, today) {
name: item.masterValues.title + " " + item.masterValues["short-description"],
price,
priceHistory: [{ date: today, price }],
unit
unit,
bio: item.masterValues.biolevel === "Bio"
});
}
return canonicalItems;
@ -54,7 +55,8 @@ function billaToCanonical(rawItems, today) {
name: item.data.name,
price: item.data.price.final,
priceHistory: [{ date: today, price: item.data.price.final }],
unit: item.data.grammagePriceFactor == 1 ? item.data.grammage : "kg"
unit: item.data.grammagePriceFactor == 1 ? item.data.grammage : "kg",
bio: item.data.attributes && item.data.attributes.includes("s_bio")
});
}
return canonicalItems;
@ -70,7 +72,8 @@ function hoferToCanonical(rawItems, today) {
name: item.ProductName,
price: item.Price,
priceHistory: [{ date: today, price: item.Price }],
unit: `${item.Unit} ${item.UnitType}`
unit: `${item.Unit} ${item.UnitType}`,
bio: item.IsBio
});
}
return canonicalItems;

View File

@ -148,7 +148,7 @@ function itemToDOM(item) {
let componentId = 0;
function searchItems(items, query, billa, spar, hofer, eigenmarken, minPrice, maxPrice, exact) {
function searchItems(items, query, billa, spar, hofer, eigenmarken, minPrice, maxPrice, exact, bio) {
query = query.trim();
if (query.length < 3) return [];
@ -197,6 +197,7 @@ function searchItems(items, query, billa, spar, hofer, eigenmarken, minPrice, ma
if (item.price < minPrice) continue;
if (item.price > maxPrice) continue;
if (eigenmarken && !(name.indexOf("clever") == 0 || name.indexOf("s-budget") == 0 || name.indexOf("milfina") == 0)) continue;
if (bio && !item.bio) continue;
hits.push(item);
}
}
@ -213,6 +214,7 @@ function newSearchComponent(parentElement, items, searched, filter, headerModifi
<label><input id="spar-${id}" type="checkbox" checked="true"> Spar</label>
<label><input id="hofer-${id}" type="checkbox" checked="true"> Hofer</label>
<label><input id="eigenmarken-${id}" type="checkbox"> Nur CLEVER / S-BUDGET / MILFINA</label>
<label><input id="bio-${id}" type="checkbox"> Nur Bio</label>
</div>
<div class="filters">
<label>Min <input id="minprice-${id}" type="number" min="0" value="0"></label>
@ -227,6 +229,7 @@ function newSearchComponent(parentElement, items, searched, filter, headerModifi
const exact = parentElement.querySelector(`#exact-${id}`);
const table = parentElement.querySelector(`#result-${id}`);
const eigenmarken = parentElement.querySelector(`#eigenmarken-${id}`);
const bio = parentElement.querySelector(`#bio-${id}`);
const billa = parentElement.querySelector(`#billa-${id}`);
const spar = parentElement.querySelector(`#spar-${id}`);
const hofer = parentElement.querySelector(`#hofer-${id}`);
@ -239,7 +242,7 @@ function newSearchComponent(parentElement, items, searched, filter, headerModifi
try {
hits = searchItems(items, query,
billa.checked, spar.checked, hofer.checked, eigenmarken.checked,
toNumber(minPrice.value, 0), toNumber(maxPrice.value, 100), exact.checked
toNumber(minPrice.value, 0), toNumber(maxPrice.value, 100), exact.checked, bio.checked
);
} catch (e) {
console.log("Query: " + query + "\n" + e.message);