-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to add new filters? #554
Comments
@macrozone didn't you find it useful, https://docs.unchained.shop/advanced-config/filter/ |
unfortunatly not, i extended @pozylon do you have an idea? |
@macrozone Yes it's cached, the cache is invalidated for products and categories that are changed and on every start/restart of the app unless you have set "skipInvalidationOnStartup" to true. For performance reasons when you have a lot of filters, products and categories you don't want to run the cache invalidation on boot. |
that was the missing piece. would be be good to have a command for that instead ideally. |
i m sorry, i closed this prematurly. I could not make it work. Some step is missing in the documentation. It seems all filters need to be seeded first in the database, and even that is not enough to make it work. Some piece is missing. @pozylon i will update my MR with more information in the project. |
additional information: i created the custom filter as well through the unchained control panel |
ok i see now that i have to add this filter to each and very assortment. How can i add filters easily for all assortments? and even if I add filters for each assortment, how can i also enable this filter for the generic search that does not take an assortment? |
If you want to enable a global filter, you can implement const defaultSelector = ({ filterIds, filterQuery, includeInactive }: SearchQuery) => {
const selector: Query = {};
const keys = (filterQuery || []).map((filter) => filter.key);
if (Array.isArray(filterIds)) {
// return predefined list
selector._id = { $in: filterIds };
} else if (keys.length > 0) {
// return filters that are part of the filterQuery
selector.key = { $in: keys };
} else {
// do not return filters
return null;
}
if (!includeInactive) {
// include only active filters
selector.isActive = true;
}
return selector;
}; So you could do the following to enable a global filter when searching: async transformFilterSelector(last) {
// eslint-disable-line
const { searchQuery = {} } = params;
const { queryString, filterIds } = searchQuery;
if (queryString && !filterIds) {
return {
...(last || {}),
_id: {
$in: [
GLOBAL_FILTER_ID,
],
},
};
}
return last;
}, |
How can i add a custom filter which i can pass as key-value to
filterQuery
?i have a custom meta data on a product and i want to add a filter that filters by that. how can i do that?
there is a
transformProductSelector
function, but its not called (or only with undefined key and value), so i assume it uses some caching. I don't see anything in the docs how to update this cache for all existing products.The text was updated successfully, but these errors were encountered: