Reputation: 35
The project I'm working on a E-commerce app and I'm trying to show the list of orders that the user add in a recyclerview
the Problem I'm having is that all the details of the user appear except the orders that the user added doesn't show up and no error appear when I run the application
The collection of the User detail and Item that is been ordered
The code that I use
private void orderList() {
final List<List<DocumentSnapshot>> productOrder = new ArrayList<>();
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference userCartOrder = db.collection("UserOrder").document().collection("cartID");
CollectionReference userCartID = db.collection("ItemOrder");
Query query = userCartID.whereEqualTo("cartID",userCartOrder);
query.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()){
for (QueryDocumentSnapshot documentSnapshot: task.getResult()){
CollectionReference cartOrderID = documentSnapshot.getReference().collection("itemList");
cartOrderID.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()){
productOrder.add(task.getResult().getDocuments());
}
}
});
}
}
else {
Toast.makeText(AdminOrderActivity.this, "Query failed", Toast.LENGTH_SHORT).show();
}
}
});
}
Upvotes: 0
Views: 51
Reputation: 598740
The problem is like there:
CollectionReference userCartOrder = db.collection("UserOrder").document().collection("cartID");
When you call document()
without any parameter, it generates a reference to a new, unique, non-existing document. Passing that to a query, will not return any orders, as the document doesn't exist.
If you want to query the ItemOrder
of a specific cartID
, you will need to pass that cart ID to the query. For example:
Query query = userCartID.whereEqualTo("cartID", "220225073844244");
Upvotes: 1