PhoenixKitEcommerce.Import.CSVParser (PhoenixKitEcommerce v0.1.14)

Copy Markdown View Source

Parse Shopify CSV and group rows by Handle.

Shopify CSV structure:

  • First row with product data contains title, description, etc.
  • Subsequent rows for same Handle contain variant data only (empty title/description)
  • Each variant row has Option1/Option2 values and prices

Summary

Functions

A human-readable name for a group key, for logs and result tuples.

The handle to import a group under — nil for a group the file gave no handle, so the product's slug is derived from its title instead.

Get the first (main) row for a product group. Contains title, description, and other product-level data.

Parse CSV file and group rows by Handle (product identifier).

Get all variant rows (rows with price data).

Functions

display_handle(key)

A human-readable name for a group key, for logs and result tuples.

handle_value(key)

The handle to import a group under — nil for a group the file gave no handle, so the product's slug is derived from its title instead.

main_row(rows)

Get the first (main) row for a product group. Contains title, description, and other product-level data.

parse_and_group(file_path)

Parse CSV file and group rows by Handle (product identifier).

Returns a map where keys are handles and values are lists of row maps.

Examples

CSVParser.parse_and_group("/path/to/products.csv")
# => %{
#   "product-handle" => [
#     %{"Handle" => "product-handle", "Title" => "Product", ...},
#     %{"Handle" => "product-handle", "Option1 Value" => "Small", ...},
#     ...
#   ],
#   ...
# }

variant_rows(rows)

Get all variant rows (rows with price data).