categories.py•1.07 kB
"""Category search endpoints for the OCC client."""
from __future__ import annotations
from app.models import JsonObject
from app.settings import settings
from app.utils import clean_params, coalesce_fields
from .base import SupportsOccHttp
class CategoriesMixin:
async def get_products_by_category(
self: SupportsOccHttp,
base_site_id: str,
category_id: str,
*,
current_page: int = 0,
page_size: int = 20,
sort: str | None = None,
query: str | None = None,
fields: str | None = None,
) -> JsonObject:
"""Retrieve products within the specified category."""
params = clean_params(
{
"fields": coalesce_fields(fields, settings.occ_default_fields),
"currentPage": current_page,
"pageSize": page_size,
"sort": sort,
"query": query,
}
)
path = f"/{base_site_id}/categories/{category_id}/products"
return await self.get_json(path, params=params)