diff --git a/app/services/migration_engine/upsert_executor.py b/app/services/migration_engine/upsert_executor.py index e75a329..dc33a52 100644 --- a/app/services/migration_engine/upsert_executor.py +++ b/app/services/migration_engine/upsert_executor.py @@ -484,6 +484,20 @@ class UpsertExecutor: if val: all_attributes[key] = val + # Auto-infer color from variant name or media_key if not explicitly provided + if not mapped_row.get("color") and not all_attributes.get("color"): + var_name = str(mapped_row.get("name") or "").strip() + if " - " in var_name: + suffix = var_name.split(" - ", 1)[1].strip() + if suffix and suffix.lower() not in {"n/a", "na", "none", "null", "-", "true", "false", "undefined"}: + all_attributes["color"] = suffix + elif mapped_row.get("media_key"): + mk = mapped_row["media_key"].lower().replace("_", "-") + for c_cand in ["forest-blue", "hot-pink", "marshmallow-blue", "black", "white", "blue", "pink", "green", "red", "gold", "silver", "grey", "gray", "purple"]: + if mk.endswith(c_cand) or f"-{c_cand}-" in mk: + all_attributes["color"] = c_cand.replace("-", " ").title() + break + # Filter meaningful attributes for variant display & mapping (ignore placeholders & boolean flags) # NOTE: media_key/parent_media_key are intentionally excluded here to keep specs display clean, # but they MUST be saved separately below so the MEDIA_LINK phase can match them.