Overview
The Order Management endpoint retrieves all orders for a specific tenant. This endpoint is primarily used in the tenant dashboard to display order history and analytics.Authentication Required: This endpoint requires user authentication via Laravel’s
auth middleware.Plan Restriction: Only tenants with the
cat-anual plan have access to order data. Other plans will receive an empty order list.Get Tenant Orders
Retrieve all orders for a tenant, sorted by date (most recent first).The unique tenant identifier
Response
Returns an HTML view (dashboard.components.orders-section) with the following data:
Array of order objects sorted by date (descending)
Tenant model with plan relationship loaded
Whether the tenant has the
cat-anual planOrder Data Structure
Each order in theorders array contains the following fields:
Unique order identifier (format:
SC-XXXXXX)Tenant owner ID
ISO 8601 timestamp with timezone (e.g.,
2026-03-08T15:30:45+00:00)Customer information
Order line items
Total order value (sum of all items)
Currency code (always
REF for Venezuelan reference)Order channel (always
whatsapp)Example Order Object
Storage Architecture
File System Organization
Orders are stored as individual JSON files in the Laravel storage directory:Benefits of File-Based Storage
Performance
Performance
JSON files provide fast read access without database queries. The controller loads all orders in a single directory scan.
Scalability
Scalability
Monthly partitioning prevents directory bloat. Each month starts fresh, keeping file counts manageable.
Backup & Archival
Backup & Archival
Year/month folders make it easy to archive old orders or backup specific time periods.
Portability
Portability
Orders can be easily exported, transferred, or processed by external tools without database dependencies.
Retrieval Process
TheOrdersController::index method:
- Validates tenant exists and loads plan relationship
- Checks if tenant has
cat-anualplan - If no access, returns empty view
- Scans
storage/app/tenants/{tenantId}/orders/recursively - Filters for
.jsonfiles only - Decodes each JSON file to array
- Validates order has
idfield - Sorts by
datefield descending - Returns Blade view with order data
/workspace/source/app/Http/Controllers/OrdersController.php:27-42
Plan Access Control
cat-anual Plan Requirement
Only tenants with the cat-anual plan can:- Create orders via the Checkout API
- View order history via this endpoint
- Access order management features
Plan Check Logic
$isPlanAnual is false:
- Returns view with empty
ordersarray isPlanAnualset tofalsein view data- UI typically shows upgrade prompt
Date Sorting
Orders are sorted by thedate field in descending order (newest first):
Date Comparison Behavior
- Uses lexicographic string comparison on ISO 8601 dates
- Handles missing
datefields gracefully (treats as empty string) - More recent dates appear first in the array
Integration Examples
Dashboard Order Display
JavaScript Order Analytics
Advanced Order Retrieval
Filtering by Date Range
To retrieve orders from a specific time period, filter the file paths:Search by Order ID
Customer Order History
Performance Considerations
File Count Impact
Current Implementation: Scans all order files recursively. Performance may degrade with thousands of orders.
- For high-volume tenants, consider adding database indexing
- Implement pagination for large order sets
- Cache aggregated statistics (total orders, revenue, etc.)
Directory Scan Optimization
TheStorage::allFiles() method recursively scans all subdirectories. For better performance:
Caching Strategy
Related Endpoints
Checkout API
Create new orders and comandas
Tenant Authentication
PIN verification for tenant access
Analytics Tracking
Track order conversion events
Dashboard API
Tenant management endpoints
Troubleshooting
Empty Order List
Tenant lacks cat-anual plan
Tenant lacks cat-anual plan
Symptom: Orders exist in storage but not displayedSolution: Verify
$tenant->plan->slug === 'cat-anual'. Upgrade tenant plan if needed.No order files in storage
No order files in storage
Symptom: Directory
storage/app/tenants/{id}/orders/ is emptySolution: Check if orders were created via Checkout API. Verify file permissions on storage directory.Malformed JSON files
Malformed JSON files
Symptom: Files exist but not parsed correctlySolution: Validate JSON syntax. Ensure
id field exists in each order object.Incorrect Sorting
Symptom: Orders appear in wrong date order Causes:- Missing or null
datefield in order objects - Date format inconsistency (non-ISO 8601)
- Server timezone configuration issues
date values. Use now()->toIso8601String() when creating orders.
Authentication Errors
Symptom: 401 Unauthorized or redirect to login Solution: This endpoint requires Laravel authentication. Ensure:- User is logged in via
authmiddleware - Session cookie is valid
- User has permission to access the tenant
Future Enhancements
Pagination
Limit orders per page for performance
JSON API Response
Return JSON instead of HTML view
Advanced Filters
Filter by date range, customer, status
Export to CSV/Excel
Download order reports