Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/AndresLopezCorrales/La-casa-del-bordadito/llms.txt

Use this file to discover all available pages before exploring further.

The cart and checkout flow in La Casa del Bordadito ties together the menu, payment preferences, and order history into one seamless screen sequence. Items land in a live Firestore cart, a running total updates in real time, and completing a purchase generates a QR code that serves as the customer’s digital receipt — ready to be scanned at the counter.

Adding items to the cart

Items can be added from two places:

Café fragment quick-add

The + button (btnAddCafe) on each card in the grid view calls anadirAlCarrito directly from FragmentCafe. The app selects the first key from the tamano map as the default size and writes the item to Firestore immediately.

Detail screen add

Tapping any café item opens DetalleCafeActivity. The customer picks a specific size from the RadioGroup, then taps Agregar to add the item with the chosen size and price.
The same quick-add logic is also available from the home screen (FragmentInicio) via CafeInicioAdapter.

CarritoItem model

data class CarritoItem(
    var carritoItemId: String = "",
    var nombre: String = "",
    var tamano: String = "",
    var precio: Double = 0.0,
    var cantidad: Int = 1,
    var imagenUrl: String = ""
) : Serializable
FieldTypeDescription
carritoItemIdStringSource item ID (Firestore cafes document ID, or bordado_{patronId})
nombreStringDisplay name
tamanoStringSelected size (e.g. "Mediano")
precioDoubleUnit price in MXN
cantidadIntQuantity; defaults to 1, incremented on duplicate adds
imagenUrlStringImage URL for the cart row

Item ID format and quantity merging

The Firestore document ID for each cart item is constructed as "{carritoItemId}_{tamano}", for example "abc123_Mediano". Before writing, the app checks whether that document already exists:
  • Exists → increments cantidad by 1.
  • Does not exist → creates a new document with cantidad = 1.
This means adding the same drink in the same size multiple times accumulates quantity rather than duplicating rows.

Firestore cart path

carritos/{uid}/items/{carritoItemId}_{tamano}
CarritoActivity attaches a snapshot listener to this subcollection via escucharCarrito(). Every change — including adds from other screens — is reflected live in the cart list and running total.
The cart badge in MainActivity’s bottom navigation also updates in real time via a Firestore snapshot listener on the same carritos/{uid}/items path. The badge count equals the total number of distinct item documents in the subcollection.

Cart screen

CarritoActivity presents a RecyclerView of cart items, a live txtTotal showing the running sum in MXN, and a MaterialButtonToggleGroup for selecting the payment method.
Payment toggleBehaviour
Efectivo (Cash)Selected by default; calls procesarCompra("Efectivo") immediately on purchase
CardOpens a card-selection dialog populated from saved payment methods in Realtime DB (Usuarios/{uid}/metodosPago)
If the card toggle is selected but the user has no saved cards, a dialog prompts them to add a card first via TarjetaAgregarActivity.

Order processing

1

Create order document

procesarCompra writes a new document to the ordenes Firestore collection containing the user’s email, total, timestamp, item list, and payment method. Firestore auto-generates the order ID.
2

Clear the cart

After the order is confirmed, a Firestore batch delete removes every document from carritos/{uid}/items.
3

Navigate to QR screen

The app starts QRActivity, passing ordenId, usuario, total, items (as a Serializable ArrayList<CarritoItem>), and metodoPago as intent extras.

Sample Firestore orden document

{
  "usuario": "cliente@ejemplo.com",
  "total": "85.0 MXN",
  "fecha": 1718200000000,
  "metodoPago": "Tarjeta (Visa ****4242)",
  "items": [
    {
      "carritoItemId": "abc123",
      "nombre": "Café de Olla",
      "tamano": "Mediano",
      "precio": 45.0,
      "cantidad": 1,
      "imagenUrl": "https://firebasestorage.googleapis.com/.../cafe_de_olla.jpg"
    },
    {
      "carritoItemId": "def456",
      "nombre": "Empanada de Cajeta",
      "tamano": "Único",
      "precio": 40.0,
      "cantidad": 1,
      "imagenUrl": "https://firebasestorage.googleapis.com/.../empanada.jpg"
    }
  ]
}

QR receipt

QRActivity uses the ZXing library (BarcodeEncoder) to generate an 800 × 800 px QR code bitmap. The encoded JSON payload includes:
{
  "id": "ORDENFIRESTORE123",
  "user": "cliente@ejemplo.com",
  "total": "85.0 MXN",
  "date": "12/06/2025 14:32",
  "payment": "Tarjeta (Visa ****4242)",
  "items": [
    { "name": "Café de Olla", "size": "Mediano", "qty": 1, "price": 45.0 },
    { "name": "Empanada de Cajeta", "size": "Único", "qty": 1, "price": 40.0 }
  ]
}
The on-screen receipt below the QR code shows a human-readable folio (last 8 characters of the order ID, uppercased), client email, date, payment method, itemised breakdown, and the total paid.

Build docs developers (and LLMs) love