# UseCategory Composable
Base (Methods, Interfaces, Properties)
# Features
- search a list of categories.
# API
A Category in odoo can have a parent.
type Category = {
id: number;
name: string;
slug: string;
parent?: Category;
childs?: Category[];
products?: Product[];
}
# Params
The base Graphql params is
export type GraphQlGetCategoryParams = {
filter: CategoryFilterInput;
currentPage?: number;
pageSize?: number;
search?: string;
sort?: CategorySortInput;
};
export type CategoryFilterInput = {
id: number;
parent: boolean;
};
export type CategorySortInput = {
id: SortEnum;
};
export enum SortEnum {
ASC,
DESC
}
# Example
import { useCategory } from '@vue-storefront/odoo';
import { onSSR } from '@vue-storefront/core'
export default {
setup () {
const { search, categories } = useCategory();
onSSR(async () => {
await search({
filter: { parent: true }, // Optional filter
pageSize: 12, // Optional filter
customQuery: { getCategory: 'customGetCategoryQuery' } // Optional custom query
});
});
return {
categories,
loading
}
}
}