PhoenixKitCatalogue.Catalogue.Manufacturers (PhoenixKitCatalogue v0.18.0)

Copy Markdown View Source

Manufacturers — company directory used as the source of items.

Hard-deletes only (manufacturers are reference data, not user content). Status field is "active" / "inactive"; inactive manufacturers remain in the DB but are filtered from item dropdowns.

Public surface is re-exported from PhoenixKitCatalogue.Catalogue via defdelegate, so callers can keep using the canonical context module.

Summary

Functions

Returns a changeset for tracking manufacturer changes.

Creates a manufacturer.

Hard-deletes a manufacturer from the database.

Fetches a manufacturer by UUID. Returns nil if not found.

Fetches a manufacturer by UUID. Raises Ecto.NoResultsError if not found.

Stamps :manufacturer_name on each item — the replacement for the preload(:manufacturer) that V179's federated reference made impossible.

Every item this CRM party is recorded as the manufacturer of, for the catalogue panel on that party's page in CRM.

Lists manufacturers from all available sources as normalized maps.

Lists all manufacturers, ordered by name.

Resolves a manufacturer UUID to a unified map regardless of source.

Batch form of resolve/1 — see PhoenixKitCatalogue.Catalogue.Suppliers.resolve_many/1. This is the call that hydrates a page of items without one cross-module lookup per row.

Updates a manufacturer with the given attributes.

Functions

change_manufacturer(manufacturer, attrs \\ %{})

Returns a changeset for tracking manufacturer changes.

create_manufacturer(attrs, opts \\ [])

Creates a manufacturer.

Required attributes

  • :name — manufacturer name (1-255 chars)

Optional attributes

  • :description, :website, :contact_info, :logo_url, :notes
  • :status"active" (default) or "inactive"
  • :data — flexible JSON map

delete_manufacturer(manufacturer, opts \\ [])

Hard-deletes a manufacturer from the database.

get_manufacturer(uuid)

@spec get_manufacturer(Ecto.UUID.t()) ::
  PhoenixKitCatalogue.Schemas.Manufacturer.t() | nil

Fetches a manufacturer by UUID. Returns nil if not found.

get_manufacturer!(uuid)

Fetches a manufacturer by UUID. Raises Ecto.NoResultsError if not found.

hydrate(item)

Stamps :manufacturer_name on each item — the replacement for the preload(:manufacturer) that V179's federated reference made impossible.

One call per page, two queries at most, whatever mix of local and CRM manufacturers the page contains. Items whose reference resolves to nothing fall back to their stored manufacturer_name_snapshot, and then to nil, so a deleted party degrades to the last known name rather than a blank.

Accepts a single item or a list, and is a no-op for anything without a manufacturer.

items_manufactured_by(party_uuid)

@spec items_manufactured_by(Ecto.UUID.t()) :: [PhoenixKitCatalogue.Schemas.Item.t()]

Every item this CRM party is recorded as the manufacturer of, for the catalogue panel on that party's page in CRM.

Matches the party's own uuid AND any local manufacturer row projecting it, so items that still store the pre-move local uuid are included. Deleted items excluded.

list_all(opts \\ [])

@spec list_all(keyword()) :: [map()]

Lists manufacturers from all available sources as normalized maps.

CRM parties holding an active manufacturer role come first, then local rows ordered by name. Local rows already linked to a CRM party are omitted: the party side of the same company is in the list already, and emitting both would show one company twice.

list_manufacturers(opts \\ [])

@spec list_manufacturers(keyword()) :: [PhoenixKitCatalogue.Schemas.Manufacturer.t()]

Lists all manufacturers, ordered by name.

Options

  • :status — filter by status (e.g. "active", "inactive"). When nil (default), returns all manufacturers.

resolve(uuid)

@spec resolve(Ecto.UUID.t()) :: {:ok, map()} | :error

Resolves a manufacturer UUID to a unified map regardless of source.

Returns {:ok, map} with keys :uuid, :name, :email, :phone, :website, :source (:crm | :local), or :error when the uuid is unknown to both sources. CRM is consulted first and only when the CRM module is loaded.

resolve_many(uuids)

@spec resolve_many([Ecto.UUID.t()]) :: %{required(Ecto.UUID.t()) => map()}

Batch form of resolve/1 — see PhoenixKitCatalogue.Catalogue.Suppliers.resolve_many/1. This is the call that hydrates a page of items without one cross-module lookup per row.

update_manufacturer(manufacturer, attrs, opts \\ [])

Updates a manufacturer with the given attributes.