PhoenixKit.Modules.Shop.Category (phoenix_kit v1.7.42)

Copy Markdown View Source

Category schema for product organization.

Supports hierarchical nesting via parent_id.

Fields

  • name - Category name (required)
  • slug - URL-friendly identifier (unique)
  • description - Category description
  • featured_product_id - Featured product for fallback image
  • parent_id - Parent category for nesting
  • position - Sort order
  • status - Category status: "active", "hidden", "archived"
  • metadata - JSONB for custom fields
  • option_schema - Category-specific product option definitions (JSONB array)

Status Values

  • active - Category and products visible in storefront
  • unlisted - Category hidden from menu, but products still visible
  • hidden - Category and all products hidden from storefront

Summary

Functions

Returns true if category is active (visible in storefront).

Returns the full path of category names from root to this category. Requires parent to be preloaded.

Changeset for category creation and updates.

Returns the image URL for a category.

Returns true if category has children.

Returns true if category is hidden (category and products not visible).

Returns the list of localized field names.

Returns true if products in this category should be visible in storefront. Products are visible when category is active or unlisted.

Returns true if category is a root category (no parent).

Returns true if category should appear in category menu/list. Only active categories appear in the menu.

Returns list of valid category statuses

Returns true if category is unlisted (not in menu, but products visible).

Types

t()

@type t() :: %PhoenixKit.Modules.Shop.Category{
  __meta__: term(),
  children: term(),
  description: term(),
  featured_product: term(),
  featured_product_id: term(),
  featured_product_uuid: term(),
  id: term(),
  image_id: term(),
  inserted_at: term(),
  metadata: term(),
  name: term(),
  option_schema: term(),
  parent: term(),
  parent_id: term(),
  parent_uuid: term(),
  position: term(),
  products: term(),
  slug: term(),
  status: term(),
  updated_at: term(),
  uuid: term()
}

Functions

active?(arg1)

Returns true if category is active (visible in storefront).

changeset(category, attrs)

Changeset for category creation and updates.

get_image_url(category, opts \\ [])

Returns the image URL for a category.

Priority:

  1. Storage media (image_id) if available
  2. Featured product's featured_image_id (requires :featured_product preloaded)
  3. Featured product's legacy featured_image URL (requires :featured_product preloaded)
  4. nil if no image

Options

  • :size - Storage dimension to use (default: "large")

has_children?(arg1)

Returns true if category has children.

hidden?(arg1)

Returns true if category is hidden (category and products not visible).

localized_fields()

Returns the list of localized field names.

products_visible?(arg1)

Returns true if products in this category should be visible in storefront. Products are visible when category is active or unlisted.

root?(category)

Returns true if category is a root category (no parent).

show_in_menu?(arg1)

Returns true if category should appear in category menu/list. Only active categories appear in the menu.

statuses()

Returns list of valid category statuses

unlisted?(arg1)

Returns true if category is unlisted (not in menu, but products visible).