fix product page

This commit is contained in:
Phuoc Nguyen
2025-11-17 11:03:51 +07:00
parent 49082026f5
commit 0828ff1355
17 changed files with 482 additions and 76 deletions

View File

@@ -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;

View File

@@ -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) {