fix(migration): auto-infer color from variant name and media_key
This commit is contained in:
parent
211666347e
commit
7c7c474e47
1 changed files with 14 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue