Hi,
Hoping you can help in advance with what I'm sure is an extremely simple and quick fix, however despite trying several things my extremely limited ability has failed...
We have two optional Checkbox Group filters that customers can apply to a product dataset to filter products of a certain brand and/or products within a certain category. All are ultimately Wix product collections.
Last week our filters stopped working correctly.
Previously a user could select one or multiple options from either Checkbox Groups and the subsequent results would be exactly as you'd expect; selecting Brand A shows 7 products that in the Brand A collection, selecting Category Z shows 9 products in the Category Z collection, selecting Brand A and Category Z shows 16 products that could appear in either Brand A or Category Z collections.
However, now, as soon as any Checkbox option is selected, it returns with 0 results.
Here is the filter part of the code (obviously happy to provide more if needed?):
async function filter(name, collection) {
if (filterName !== name || collectionName !== collection) {
let newFilter = wixData.filter();
if (name)
newFilter = newFilter.contains('name', name);
if (collection)
newFilter = newFilter.hasAll('collections', ["7a803baf-9a2a-4c4a-8fdf-d1bf5cd343fe"]);
newFilter = newFilter.hasSome('collections', $w('#checkboxGroup1').value);
newFilter = newFilter.hasSome('collections', $w('#checkboxGroup2').value);
await $w("#dataset1").setFilter(newFilter);
if (defaultSort === true) {
$w("#dataset1").setSort(wixData.sort()
.descending("name")
);
}
let count = $w("#dataset1").getTotalCount();
$w("#count").text = 'Total Products: (' + count + ')';
filterName = name;
collectionName = collection;
// waits and updates the checkbox options
setTimeout(() => {
defineCategories();
}, 50);
}
}
The area that doesn't SEEM to be working anymore is as follows:
if (collection) newFilter = newFilter.hasAll('collections', ["7a803baf-9a2a-4c4a-8fdf-d1bf5cd343fe"]); //this is the collection unique to this page newFilter = newFilter.hasSome('collections', $w('#checkboxGroup1').value); //this is the Category dropdown checkbox group newFilter = newFilter.hasSome('collections', $w('#checkboxGroup2').value); //this is the Brand dropdown checkbox group
It appears as though the the query is now looking for data where Brand collections are blank (they never are), and as such I THINK I should be using the or() statement between the .hasSome statements - does that sound remotely correct?
Any help/guidance would be extremely appreciated as have spent many hours trying and ultimately failing to fix what honestly feels like an extremely straightfoward solution - I just can't land on what it is!
Thank you
Ashley