我尝试将我尝试存储的产品ID存储在cartMup上,但是没有用。
这是我如何从产品活动中获取产品ID的方法:
productID = getIntent().getStringExtra("pid");
private StringproductID = "";
将数据存储到购物车列表中
private void addingToCartList() {
final HashMap<String, Object> cartMap = new HashMap<>();
cartMap.put("pid", productID);
cartMap.put("pname", productName.getText().toString());
cartMap.put("price", productPrice.getText().toString());
cartMap.put("discount", "");
cartMap.put("quantity", numberButton.getNumber());
cartMap.put("time", saveCurrentTime);
cartMap.put("date", saveCurrentDate);
cartListRef.child("User view").child(Prevalent.currentOnlineUser.getEmail()).child("Products").child(productID).updateChildren(cartMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
cartListRef.child("Admin view").child(Prevalent.currentOnlineUser.getEmail()).child("Products").child(productID).updateChildren(cartMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(ProductDetailsActivity.this, "Product added to
Cart!",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(ProductDetailsActivity.this, HomeActivity.class);
startActivity(intent);
}
}
});
}
}
});
}