fix product page
This commit is contained in:
@@ -184,13 +184,20 @@ class ProductsRemoteDataSource {
|
||||
|
||||
/// Get products by category
|
||||
///
|
||||
/// Filters products by category.
|
||||
/// For now, we fetch all products and filter locally.
|
||||
/// Filters products by category with pagination support.
|
||||
/// For now, we fetch products with pagination and filter locally.
|
||||
/// In the future, the API might support category filtering.
|
||||
Future<List<ProductModel>> getProductsByCategory(String categoryId) async {
|
||||
// For now, fetch all products and filter locally
|
||||
Future<List<ProductModel>> getProductsByCategory(
|
||||
String categoryId, {
|
||||
int limitStart = 0,
|
||||
int limitPageLength = 12,
|
||||
}) async {
|
||||
// Fetch products with pagination and filter locally
|
||||
// TODO: Implement server-side category filtering if API supports it
|
||||
final allProducts = await getAllProducts();
|
||||
final allProducts = await getAllProducts(
|
||||
limitStart: limitStart,
|
||||
limitPageLength: limitPageLength,
|
||||
);
|
||||
|
||||
if (categoryId == 'all') {
|
||||
return allProducts;
|
||||
|
||||
@@ -25,10 +25,16 @@ class ProductsRepositoryImpl implements ProductsRepository {
|
||||
});
|
||||
|
||||
@override
|
||||
Future<List<Product>> getAllProducts() async {
|
||||
Future<List<Product>> getAllProducts({
|
||||
int limitStart = 0,
|
||||
int limitPageLength = 12,
|
||||
}) async {
|
||||
try {
|
||||
// Fetch from Frappe API
|
||||
final productModels = await remoteDataSource.getAllProducts();
|
||||
// Fetch from Frappe API with pagination
|
||||
final productModels = await remoteDataSource.getAllProducts(
|
||||
limitStart: limitStart,
|
||||
limitPageLength: limitPageLength,
|
||||
);
|
||||
return productModels.map((model) => model.toEntity()).toList();
|
||||
} catch (e) {
|
||||
print('[ProductsRepository] Error getting products: $e');
|
||||
@@ -49,11 +55,17 @@ class ProductsRepositoryImpl implements ProductsRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Product>> getProductsByCategory(String categoryId) async {
|
||||
Future<List<Product>> getProductsByCategory(
|
||||
String categoryId, {
|
||||
int limitStart = 0,
|
||||
int limitPageLength = 12,
|
||||
}) async {
|
||||
try {
|
||||
// Filter by category via remote API
|
||||
// Filter by category via remote API with pagination
|
||||
final productModels = await remoteDataSource.getProductsByCategory(
|
||||
categoryId,
|
||||
limitStart: limitStart,
|
||||
limitPageLength: limitPageLength,
|
||||
);
|
||||
return productModels.map((model) => model.toEntity()).toList();
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user