Build option values and price modifiers from Shopify variant rows.
Extracts Option1..Option10 names and values from CSV rows, calculates base price (minimum) and price modifiers (deltas from base).
Extended Support
- Supports Option1 through Option10 (Shopify standard)
- Accepts option_mappings for slot-based options
- Builds _option_slots structure for products using global options
Summary
Functions
Build extended options data from variant rows.
Build options data from variant rows (legacy format).
Functions
Build extended options data from variant rows.
Supports Option1 through Option10 and optional slot mappings.
Arguments
rows- List of CSV row maps for a single productopts- Keyword options::option_mappings- List of mapping configs from ImportConfig
Returns
Map with:
base_price- Minimum variant priceoptions- List of option data for each option foundoption_slots- Slot definitions if mappings provided
Examples
# Without mappings (standard import)
OptionBuilder.build_extended(rows)
# => %{
# base_price: Decimal.new("22.80"),
# options: [
# %{position: 1, name: "Size", values: [...], modifiers: %{...}},
# %{position: 2, name: "Cup Color", values: [...]},
# %{position: 3, name: "Liquid Color", values: [...]}
# ],
# option_slots: []
# }
# With mappings (slot-based import)
mappings = [
%{"csv_name" => "Cup Color", "slot_key" => "cup_color", "source_key" => "color"},
%{"csv_name" => "Liquid Color", "slot_key" => "liquid_color", "source_key" => "color"}
]
OptionBuilder.build_extended(rows, option_mappings: mappings)
# => %{
# base_price: Decimal.new("22.80"),
# options: [...],
# option_slots: [
# %{slot: "cup_color", source_key: "color", label: "Cup Color", values: [...]},
# %{slot: "liquid_color", source_key: "color", label: "Liquid Color", values: [...]}
# ]
# }
Build options data from variant rows (legacy format).
Returns a map with:
- base_price: minimum variant price (Decimal)
- option1_name: name of first option (e.g., "Size")
- option1_values: list of unique values for option1
- option1_modifiers: map of value => price delta from base
- option2_name: name of second option (e.g., "Color")
- option2_values: list of unique values for option2
Examples
OptionBuilder.build_from_variants(rows)
# => %{
# base_price: Decimal.new("22.80"),
# option1_name: "Size",
# option1_values: ["4 inches (10 cm)", "5 inches (13 cm)", ...],
# option1_modifiers: %{"4 inches (10 cm)" => "0", "5 inches (13 cm)" => "5.00", ...},
# option2_name: "Color",
# option2_values: ["Black", "White", ...]
# }