Overview
The category management system provides a hierarchical organization structure for your products. You can create main categories and nested subcategories, each with custom colors and status settings. This enables efficient product classification and filtering across your inventory.Key Features
- Create unlimited categories and subcategories
- Visual color palette with 10+ preset colors
- Hierarchical organization (categories → subcategories)
- Status management (ACTIVO/INACTIVO)
- Real-time search and filtering
- Color inheritance for subcategories
- Duplicate name prevention
Data Structure
Categories
| Field | Type | Required | Max Length | Description |
|---|---|---|---|---|
id | Integer | Auto | - | Unique identifier |
nombre | String | Yes | 50 chars | Category name (unique) |
descripcion | String | No | 200 chars | Category description |
color | String | Yes | 7 chars | Hex color code (e.g., #2e6df6) |
estado | Enum | Yes | - | ACTIVO or INACTIVO |
fecha_creacion | DateTime | Auto | - | Creation timestamp |
fecha_actualizacion | DateTime | Auto | - | Last update timestamp |
Subcategories
Subcategories have all category fields plus:| Field | Type | Required | Description |
|---|---|---|---|
categoria_id | Integer | Yes | Parent category reference |
User Workflows
Creating a Category
Enter category details
Fill in the form:
- Nombre (required, max 50 chars): Unique category name
- Descripción (optional, max 200 chars): Additional details
- Color: Click a color swatch from the palette
- Estado: Select ACTIVO or INACTIVO
Creating a Subcategory
You must have at least one category before creating subcategories.
Select parent category
Choose the parent category from the dropdown. The subcategory will inherit the parent’s color by default.
Enter subcategory details
- Categoría (required): Parent category
- Nombre (required, max 50 chars): Subcategory name
- Descripción (optional, max 200 chars)
- Color: Auto-filled from parent, but can be changed
- Estado: ACTIVO or INACTIVO
When you select a parent category, the color picker automatically updates to match the parent’s color. You can override this if needed.
Editing Categories/Subcategories
Deleting Categories/Subcategories
Switching Between Categories and Subcategories
The interface has two modes accessible via top toolbar buttons:- Categorías: Shows all main categories
- Subcategorías: Shows all subcategories with parent category names
- Updates the button text (”+ Crear Categoría” vs ”+ Crear Subcategoría”)
- Changes the search placeholder
- Reloads the appropriate data set
Color Palette
The system provides a predefined color palette for visual organization:Blue
Default category color
Red
High priority items
Green
Active/available
Yellow
Warning/attention
Purple
Premium items
Custom
More colors available in the picker
API Reference
Categories Endpoint
Subcategories Endpoint
Create Category
- Request
- Success Response
- Error Response
Create Subcategory
- Request
- Success Response
Update Category
- Request
- Success Response
Delete Category
- Request
- Success Response
- Error Response (Has Products)
Validation Rules
Name Validation
Name Validation
- Required: Cannot be empty
- Max Length: 50 characters
- Uniqueness: Must be unique across all categories (or subcategories)
- Trimming: Whitespace is automatically removed
- Validation Location: Both frontend (line 499-508) and backend (line 56-62)
Description Validation
Description Validation
- Optional: Can be left empty
- Max Length: 200 characters
- Trimming: Whitespace is automatically removed
- Validation Location: Frontend (line 510-513)
Color Validation
Color Validation
- Format: Must be hex color code (e.g., #2e6df6)
- Default: #2e6df6 (blue) if not specified
- Inheritance: Subcategories inherit parent color by default
- Change Detection: Color picker updates when parent category changes
Estado Validation
Estado Validation
- Values: ACTIVO or INACTIVO only
- Default: ACTIVO for new items
- Required: Must be specified
Subcategory Parent Validation
Subcategory Parent Validation
- Required: Must select a parent category
- Frontend Check: Validates selection before submission (line 532-536)
- Prerequisite: At least one category must exist (line 299-302)
UI Components
Category Card
Each category/subcategory displays as a card with:- Actions: Edit and delete buttons (top-right)
- Icon: Colored circle with folder icon
- Parent Name: (Subcategories only) Shows parent category
- Title: Category/subcategory name
- Description: Truncated description text
- Footer: Product count and status badge
Status Badges
Status is displayed with color coding:- ACTIVO: Green badge
- INACTIVO: Red/gray badge
status-activo and status-inactivo
Empty States
No Categories:Technical Implementation
Frontend (categorias.js)
Key Functions:cargarCategorias(filtro)- Fetches categories with optional filter (line 104)mostrarCategorias(filtro)- Renders category cards (line 122)cargarSubcategorias(filtro)- Fetches subcategories (line 220)mostrarSubcategorias(filtro)- Renders subcategory cards with parent names (line 238)abrirModalNuevaSubcategoria()- Dynamically creates category select (line 298)updateColorSwatch()- Highlights selected color (line 81)
currentMode variable (line 7) toggles between ‘categorias’ and ‘subcategorias’, affecting:
- Button text
- Search placeholder
- Modal content
- Data loading function
Backend (categorias.php)
Database Tables:categorias- Main category tablesubcategorias- Subcategory table with FK to categorias
- Line 21: SELECT with DESC ordering
- Line 87: Unique name check before INSERT
- Line 99: INSERT with automatic timestamps
- Line 187: Unique name check excluding current ID
- Line 256: Product association check before DELETE
- Line 264-273: Dynamic column detection for FK relationship
The backend uses intelligent FK column detection to support various naming conventions:
categoria_id, id_categoria, categoria, or categoriaId.Best Practices
Logical Grouping
Create categories that match your business organization (e.g., Electronics → Smartphones, Laptops)
Consistent Colors
Use color coding consistently (e.g., all food items green, electronics blue)
Descriptive Names
Keep names clear and concise within the 50-character limit
Status Management
Use INACTIVO status to hide categories without deleting historical data
Plan Hierarchy
Design your category structure before creating products for better organization
Regular Reviews
Periodically audit categories and merge duplicates or similar items
Common Error Messages
| Error Message | Cause | Solution |
|---|---|---|
| ”El nombre es obligatorio” | Empty name field | Enter a category name |
| ”El nombre no puede superar 50 caracteres” | Name too long | Shorten the name |
| ”La descripción no puede superar 200 caracteres” | Description too long | Reduce description length |
| ”Ya existe una categoría con este nombre” | Duplicate name | Choose a unique name |
| ”Debe seleccionar una categoría” | No parent selected (subcategory) | Select a parent category |
| ”Debe crear al menos una categoría primero” | Creating subcategory without categories | Create a category first |
| ”Categoría no encontrada” | Invalid ID | Refresh and try again |
| ”No se puede eliminar. Tiene X producto(s) asociado(s)“ | Products linked | Reassign products first |