PhoenixKit.Modules.Shop.Import.ProductTransformer (phoenix_kit v1.7.71)

Copy Markdown View Source

Transform Shopify CSV rows into PhoenixKit Product format.

Handles:

  • Basic product fields (title, description, price, etc.)
  • Option values and price modifiers in metadata
  • Slot-based options with global option mapping
  • Category assignment based on title keywords (configurable)
  • Image collection
  • Auto-creation of missing categories

Extended Transform

Use transform_extended/5 with option_mappings to enable slot-based options that reference global options. This allows multiple uses of the same global option in a product (e.g., cup_color and liquid_color both referencing the "color" global option).

Summary

Functions

Resolves category UUID from slug, auto-creating if necessary.

Transform a group of CSV rows (one product) into Product attrs.

Transform with extended options support (Option3..N and slot mappings).

Build an updated categories_map including any auto-created categories.

Functions

resolve_category_uuid(category_slug, categories_map, language \\ nil)

Resolves category UUID from slug, auto-creating if necessary.

If category doesn't exist, creates it with:

  • name: Generated from slug (capitalize, replace hyphens with spaces) - localized map
  • status: "active"
  • slug: The original slug - localized map

Arguments

  • category_slug: The slug string to look up
  • categories_map: Map of slug => category_uuid
  • language: Target language for localized fields (default: system default)

transform(handle, rows, categories_map \\ %{}, config \\ nil, opts \\ [])

Transform a group of CSV rows (one product) into Product attrs.

Arguments

  • handle: Product handle (slug)
  • rows: List of CSV row maps for this product
  • categories_map: Map of slug => category_uuid
  • config: Optional ImportConfig for category rules (nil = legacy defaults)
  • opts: Keyword options:
    • :language - Target language for imported content (default: system default language)

Returns

Map suitable for Shop.create_product/1

transform_extended(handle, rows, categories_map \\ %{}, config \\ nil, opts \\ [])

Transform with extended options support (Option3..N and slot mappings).

Arguments

  • handle: Product handle (slug)
  • rows: List of CSV row maps for this product
  • categories_map: Map of slug => category_uuid
  • config: Optional ImportConfig for category rules and option mappings
  • opts: Keyword options:
    • :language - Target language for imported content
    • :option_mappings - Explicit option mappings (overrides config)

Returns

Map suitable for Shop.create_product/1 with slot-based metadata if mappings provided.

update_categories_map(categories_map, category_slug)

Build an updated categories_map including any auto-created categories.

Call this after transform() to update the map for subsequent products.