Skip to main content

Overview

The catalog management system provides centralized control over product attributes including categories, colors, and sizes. Each module features a sidebar form for creating new entries and an inline table with modal-based editing.
Categories, colors, and sizes are referenced by products through foreign keys, ensuring data consistency across the system.

Categories Module

Manage product categories with descriptions (categorias.php).

Category Structure

CREATE TABLE `categoria` (
  `id_categoria` int(11) NOT NULL,
  `nombre` varchar(50) NOT NULL,
  `descripcion` text DEFAULT NULL
);

Creating Categories

The sidebar form allows quick category creation:
if(isset($_POST['add'])){
    $stmt = $conn->prepare("INSERT INTO categoria (nombre, descripcion) VALUES (?, ?)");
    $stmt->execute([$_POST['nombre'], $_POST['descripcion']]);
    header("Location: categorias.php?msg=creada");
}
  • Nombre: Category name (e.g., “Caballero”, “Dama”, “Infantil”)
  • Descripción: Optional detailed description of the category

Editing Categories

Categories are edited through a Bootstrap modal:
if(isset($_POST['update'])){
    $stmt = $conn->prepare("UPDATE categoria SET nombre = ?, descripcion = ? WHERE id_categoria = ?");
    $stmt->execute([$_POST['nombre'], $_POST['descripcion'], $_POST['id_categoria']]);
    header("Location: categorias.php?msg=actualizada");
}
Modal Trigger Function:
function abrirEditar(id, nombre, descripcion) {
    document.getElementById('edit_id').value = id;
    document.getElementById('edit_nombre').value = nombre;
    document.getElementById('edit_descripcion').value = descripcion;
    
    var myModal = new bootstrap.Modal(document.getElementById('modalEditarCat'));
    myModal.show();
}
The JavaScript function uses addslashes() in PHP to escape quotes in descriptions, preventing XSS and JavaScript injection.

Colors Module

Manage color options for products (colores.php).

Color Structure

CREATE TABLE `color` (
  `id_color` int(11) NOT NULL,
  `nombre` varchar(30) NOT NULL
);

Creating Colors

if(isset($_POST['add'])){
    $stmt = $conn->prepare("INSERT INTO color (nombre) VALUES (?)");
    $stmt->execute([$_POST['nombre']]);
    header("Location: colores.php?msg=creado");
}

Auto-Increment IDs

Color IDs are automatically assigned by the database

Descriptive Names

Use descriptive names like “Negro Nocturno” or “Azul Marino”

Example Color Data

IDNombre
1Negro Nocturno
2Blanco Pureza
3Azul Marino
4Rojo Pasión
5Gris Oxford

Updating Colors

if(isset($_POST['update'])){
    $stmt = $conn->prepare("UPDATE color SET nombre = ? WHERE id_color = ?");
    $stmt->execute([$_POST['nombre'], $_POST['id_color']]);
    header("Location: colores.php?msg=actualizado");
}

Sizes Module

Manage size options for clothing items (tallas.php).

Size Structure

CREATE TABLE `talla` (
  `id_talla` int(11) NOT NULL,
  `talla` varchar(10) NOT NULL
);

Creating Sizes

if(isset($_POST['add'])){
    $stmt = $conn->prepare("INSERT INTO talla (talla) VALUES (?)");
    $stmt->execute([$_POST['talla']]);
    header("Location: tallas.php?msg=creado");
}

Size Examples

IDTalla
1ch (chica)
2m (mediana)
3g (grande)
7ech (extra chica)
8eg (extra grande)

Updating Sizes

if(isset($_POST['update'])){
    $stmt = $conn->prepare("UPDATE talla SET talla = ? WHERE id_talla = ?");
    $stmt->execute([$_POST['talla'], $_POST['id_talla']]);
    header("Location: tallas.php?msg=actualizado");
}

Deleting Sizes

The sizes module includes delete functionality with constraint handling:
if(isset($_GET['delete'])){
    try {
        $stmt = $conn->prepare("DELETE FROM talla WHERE id_talla = ?");
        $stmt->execute([$_GET['delete']]);
        header("Location: tallas.php?msg=eliminado");
    } catch (Exception $e) {
        $error = "No se puede eliminar esta talla porque tiene registros de mercancía asociados.";
    }
}
Sizes cannot be deleted if they’re referenced by existing products. Remove or reassign products first.

Common UI Pattern

All three catalog modules share a consistent layout:
1

Sidebar Form

Left column (col-md-4) contains a form for creating new entries
2

Data Table

Right column (col-md-8) displays existing records in a sortable table
3

Inline Actions

Each row has an “Editar” button that opens a Bootstrap modal
4

Modal Editing

Modal pre-fills with current data, allowing updates without page reload

Database Relationships

Catalog tables are referenced by the main prenda table:
ALTER TABLE `prenda`
  ADD CONSTRAINT `fk_prenda_cat` FOREIGN KEY (`id_categoria`) 
      REFERENCES `categoria` (`id_categoria`),
  ADD CONSTRAINT `fk_prenda_color` FOREIGN KEY (`id_color`) 
      REFERENCES `color` (`id_color`),
  ADD CONSTRAINT `fk_prenda_talla` FOREIGN KEY (`id_talla`) 
      REFERENCES `talla` (`id_talla`);
These foreign key constraints ensure referential integrity - you cannot assign a non-existent category, color, or size to a product.

Success Messages

All modules use URL parameters for success feedback:
ParameterMessage TypeExample URL
?msg=creadaCategory createdcategorias.php?msg=creada
?msg=actualizadaCategory updatedcategorias.php?msg=actualizada
?msg=creadoColor/size createdcolores.php?msg=creado
?msg=actualizadoColor/size updatedtallas.php?msg=actualizado
?msg=eliminadoSize deletedtallas.php?msg=eliminado

Best Practices

Descriptive Names

Use clear, descriptive names for categories and colors to improve user experience

Plan Ahead

Create all needed categories, colors, and sizes before adding products

Check References

Before deleting, verify no products reference the catalog item

Standard Sizes

Use consistent size notation (ch, m, g, ech, eg) across your inventory

Inventory Management

Create products using the categories, colors, and sizes defined here

Product CRUD

Edit products and change their category, color, or size assignments

Build docs developers (and LLMs) love