8. ProductFilterComponent (Filtrado de productos en tiempo real)

8.2. Añadir métodos de filtrado en ProductService

Siempre filtramos a partir de productosOriginales, no de la lista filtrada.

Así evitamos que los filtros se encadenen de forma incorrecta.

Abrimos product.service.ts y añadimos estos métodos:

filtrarPorNombre(nombre: string) {
  const filtrados = this.productosOriginales.filter(p =>
    p.name.toLowerCase().includes(nombre.toLowerCase())
  );
  this.productosSubject.next(filtrados);
}

filtrarPorCategoria(categoria: string) {
  const filtrados = this.productosOriginales.filter(p =>
    p.category.toLowerCase().includes(categoria.toLowerCase())
  );
  this.productosSubject.next(filtrados);
}

filtrarPorActivo(soloActivos: boolean) {
  const filtrados = soloActivos
    ? this.productosOriginales.filter(p => p.active)
    : this.productosOriginales;

  this.productosSubject.next(filtrados);
}