diff --git a/backend/product/views.py b/backend/product/views.py index b49da78..68e06e8 100644 --- a/backend/product/views.py +++ b/backend/product/views.py @@ -101,7 +101,7 @@ class AllProductsView(APIView): name="sort", description=( "Sort results by one of the following fields:\n" - "`name`, `-name`, `price`, `-price`, `discount`, `-discount`, `created_at`, `-created_at`." + "`name`, `-name`, `price`, `-price`, `created_at`, `-created_at`." "\nPrefix with `-` for descending order." ), required=False, @@ -158,12 +158,12 @@ class AllProductsView(APIView): # Filter by stock status if `in_stock` is specified in_stock = request.query_params.get('in_stock', "false") == 'true' if in_stock: - products = products.filter(in_stock__gt=0) + products = products.filter(variants__in_stock__gt=0) # Filter by discount if `has_discount` is specified has_discount = request.query_params.get('has_discount', "false") == 'true' if has_discount: - products = products.filter(discount__gt=0) + products = products.filter(variants__discount__gt=0) # Search filter search_query = request.query_params.get('search', None) @@ -175,13 +175,13 @@ class AllProductsView(APIView): price_lte = request.query_params.get('price_lte', None) if price_gte: - products = products.filter(price__gte=price_gte) + products = products.filter(variants__min_price__gte=price_gte) if price_lte: - products = products.filter(price__lte=price_lte) + products = products.filter(variants__min_price__lte=price_lte) # Sorting sort_by = request.query_params.get('sort', None) - if sort_by in ['name', '-name', 'price', '-price', 'discount', '-discount', 'created_at', '-created_at']: + if sort_by in ['name', '-name', 'price', '-price', 'created_at', '-created_at']: products = products.order_by(sort_by) else: products = products.order_by('name')