def get_current_top_category(request, obj):
    if obj.__class__.__name__.lower() == "product":
        category = obj.get_current_category(request)
    else:
        category = obj

    if category is None:
        return category

    while category.parent is not None:
        category = category.parent

    return category
Returns the current top category of a product.
dataset/ETHPy150Open diefenbach/django-lfs/lfs/catalog/utils.py/get_current_top_category