Skip to main content

Overview

KAIU Natural Living’s e-commerce platform provides a seamless shopping experience for customers to browse, purchase, and track natural wellness products. The system integrates real-time inventory, multiple payment methods, and automated logistics.

Customer Shopping Flow

1

Browse Catalog

Customers explore products through an intuitive catalog with advanced filtering and search capabilities.
2

Add to Cart

Select product variants and quantities, with real-time stock validation.
3

Checkout

Complete purchase with shipping calculation and payment method selection.
4

Track Order

Monitor order status and shipping in real-time.

Product Catalog

Browsing Experience

The catalog page (src/pages/Catalogo.tsx:120-290) provides multiple ways to discover products:

Product Information

Each product card displays:
  • Product image gallery
  • Name and variant (e.g., “10ml”, “30ml”)
  • Price in Colombian Pesos (COP)
  • Benefits and category
  • Stock availability status
  • “Add to Cart” or “Out of Stock” button

Stock Management

Real-time inventory tracking ensures customers only see available products. Out-of-stock items display a badge and disabled purchase button.

Product Variants

Products can have multiple variants (sizes, formats) managed as separate SKUs with individual pricing and stock levels.

Shopping Cart

Cart Management

The cart system (src/context/CartContextDef) provides:
const addToCart = (product: Product, variant: Variant, quantity: number) => {
  // Validates stock availability
  // Updates cart state
  // Persists to localStorage
}
Features:
  • Stock validation before adding
  • Quantity limits based on available inventory
  • Duplicate detection (increases quantity instead)
Customers can adjust quantities directly in cart:
  • Increment/decrement buttons
  • Direct number input
  • Real-time total recalculation
If requested quantity exceeds stock, the system automatically caps it to available units.
Items can be removed individually or the entire cart can be cleared.Cart persists across browser sessions using localStorage:
localStorage.setItem('kaiu_cart', JSON.stringify(cartItems));

Cart Visibility

The cart icon in the navigation header shows:
  • Item count badge
  • Slide-out drawer with full cart contents
  • Running total
  • Quick access to checkout

Checkout Process

Form Validation

The checkout form (src/pages/Checkout.tsx:69-95) implements strict validation:
// Name validation
if (!/^[a-zA-ZñÑáéíóúÁÉÍÓÚ\s]+$/.test(value)) 
  return "Solo letras y espacios.";
if (value.trim().split(/\s+/).length < 2) 
  return "Ingresa Nombre y Apellido.";

// Phone validation (Colombian mobile)
if (!/^3\d{9}$/.test(value)) 
  return "Debe ser celular (3xx) de 10 dígitos.";

// Email validation
if (!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value)) 
  return "Email inválido";

Shipping Calculation

Shipping costs are calculated automatically (src/pages/Checkout.tsx:97-140):
  1. Customer selects city → System captures:
    • Department code
    • City code
    • Destination coordinates
  2. API quote request → Sends:
    {
      "city_code": "11001",
      "subdivision_code": "11",
      "line_items": [
        {
          "unit_price": 50000,
          "quantity": 1,
          "weight": 0.2,
          "dimensions": { "height": 10, "width": 10, "length": 10 }
        }
      ],
      "payment_method_code": "COD"
    }
    
  3. Receives shipping cost → Displays final total
Shipping is calculated in real-time using the logistics provider’s API. If the API fails, the system gracefully falls back to “TBD” status and allows order creation.

Payment Methods

Contra EntregaThe most popular payment method in Colombia:
  • Customer pays when receiving the package
  • Order confirmed immediately upon checkout
  • Inventory reserved instantly
  • Confirmation email sent automatically
Backend flow (backend/create-order.js:203-224):
if (orderData.payment_method_code === 'COD') {
  await InventoryService.confirmSale(orderData.line_items);
  
  // Send COD confirmation email
  const mockTransaction = {
    id: `COD-${shipmentId}`,
    status: 'PENDING_PAYMENT_ON_DELIVERY',
    payment_method: { type: 'PAGO_CONTRA_ENTREGA' }
  };
  
  sendOrderConfirmation(emailOrderPayload, mockTransaction);
}

Order Confirmation

After successful checkout:
  1. Order ID generated → Readable PIN format (e.g., #1050)
  2. Confirmation email sent → Includes:
    • Order details and items
    • Shipping address
    • Total breakdown
    • Tracking information (when available)
  3. Success page displayed → Shows order number and next steps
  4. Cart cleared → Ready for next purchase

Order Tracking

Customer Tracking Portal

The tracking page (src/pages/TrackOrder.tsx:24-193) allows customers to: Search by:
  • Order PIN (readable ID)
  • Tracking number (from carrier)
  • Database ID (UUID)
View information:
  • Order status (Pending, Shipped, Delivered, etc.)
  • Creation date
  • Carrier name
  • Tracking number with clickable link
  • Order total
const translateStatus = (status: string) => {
  const map: Record<string, string> = {
    'PENDING': 'Pendiente',
    'APPROVED': 'Aprobado',
    'PREPARING': 'En Preparación',
    'SHIPPED': 'En Tránsito (Enviado)',
    'DELIVERED': 'Entregado',
    'CANCELLED': 'Cancelado'
  };
  return map[status?.toUpperCase()] || status;
};
Tracking page supports URL parameters for instant lookup:
https://kaiu.com.co/rastreo?guide=568139
This enables:
  • Email links that auto-search
  • QR codes on shipping labels
  • Customer support quick-links

Inventory Integration

Stock Reservation System

The backend implements a two-phase commit for inventory (backend/create-order.js:98-102):
1

Reserve Stock

When order is created, stock is temporarily reserved:
await InventoryService.reserveStock(orderData.line_items);
This prevents overselling during checkout process.
2

Confirm or Release

Based on payment outcome:
  • COD: Immediately confirm (deduct from real stock)
  • Online Payment: Wait for webhook confirmation
  • Failed Order: Release reservation back to pool
If order creation fails at any point (logistics API error, database error), the system automatically releases reserved stock:
await InventoryService.releaseReserve(orderData.line_items);

Real-time Availability

Product availability updates instantly:
  • Frontend polls inventory status
  • “Out of Stock” badges appear automatically
  • Cart validation prevents checkout with unavailable items

Order Processing Backend

Complete Order Flow

The order creation endpoint (backend/create-order.js) orchestrates:
  1. Validation → Zod schema validation of all fields
  2. Stock Check → Reserve inventory or fail fast
  3. Database Entry → Create order record with PENDING status
  4. Logistics API → Create shipment with carrier
  5. Update Order → Add tracking info and external IDs
  6. Payment Handling → Process based on method (COD vs Online)
  7. Notifications → Send confirmation emails
If logistics API fails, system performs automatic rollback:
try {
  shipmentData = await LogisticsManager.createShipment(payload);
} catch (logisticsError) {
  // Cancel order in database
  await prisma.order.update({
    where: { id: dbOrder.id },
    data: { status: 'CANCELLED' }
  });
  
  // Release reserved stock
  await InventoryService.releaseReserve(orderData.line_items);
  
  return res.status(502).json({ error: 'Error creating shipment' });
}
This ensures data consistency across systems.
Orders maintain multiple identifiers:
  • Database ID: UUID (e.g., a1b2c3d4-...)
  • Readable ID: Customer-facing PIN (e.g., 1050)
  • External ID: Logistics provider reference
  • Tracking Number: Carrier-assigned guide number
const logisticsPayload = {
  ...orderData,
  external_order_id: String(dbOrder.readableId)
};

Key Features

Form Persistence

Checkout form data persists in localStorage, so customers don’t lose information if they navigate away:
localStorage.setItem('kaiu_checkout_data', JSON.stringify(formData));

Smart Validation

Real-time field validation with helpful error messages guides customers to provide correct information on first try.

Responsive Design

Catalog automatically switches between grid and list views based on screen size, optimizing for mobile shoppers.

SEO & URLs

Category and search parameters appear in URLs, allowing customers to share and bookmark specific catalog views:
/catalogo?categoria=Aceites+Esenciales&q=lavanda

API Endpoints

EndpointMethodPurpose
/api/create-orderPOSTCreate new order with logistics
/api/quote-shippingPOSTCalculate shipping cost
/api/track-orderGETRetrieve order status by ID
/api/wompi/signPOSTGenerate payment signature
/api/productsGETFetch product catalog

Admin Dashboard

Manage orders and view sales analytics

Order Management

Process and fulfill customer orders

Inventory

Track and manage product stock

Build docs developers (and LLMs) love