d
This commit is contained in:
1 parent
a11aba2564
commit
80542de333
1 file changed
+43
-42
+43
-42
@@ -286,30 +286,55 @@ async def update_itm(item_id: str, lego_set: dict, item_data: dict = None):
|
||||
print(f"[@DEBUG] Fresh variation version: {variation_version}")
|
||||
print(f"[@DEBUG] Final category_id for upsert: {category_id}")
|
||||
|
||||
# Preserve existing variation and update only what we need
|
||||
if variations:
|
||||
# Start with existing variation to preserve all fields
|
||||
variation_obj = variations[0].copy()
|
||||
variation_data = variation_obj.get("item_variation_data", {}).copy()
|
||||
# Get the full existing item_data and modify only what we need
|
||||
# This preserves ALL existing fields (location settings, tax, etc)
|
||||
existing_item_data = fresh_item.get("item_data", {})
|
||||
|
||||
# Update only the fields we want to change
|
||||
variation_data["price_money"] = {
|
||||
# Update item-level fields
|
||||
existing_item_data["name"] = pw_name
|
||||
existing_item_data["description"] = f"{set_name} - {set_theme}"
|
||||
existing_item_data["category_id"] = category_id
|
||||
|
||||
# Update only the specific variation, keep all others unchanged
|
||||
existing_variations = existing_item_data.get("variations", [])
|
||||
updated_variations = []
|
||||
variation_found = False
|
||||
|
||||
for existing_var in existing_variations:
|
||||
if existing_var.get("id") == variation_id:
|
||||
# Preserve all variation fields and only update what we need
|
||||
updated_var = existing_var.copy()
|
||||
updated_var_data = existing_var.get(
|
||||
"item_variation_data", {}
|
||||
).copy()
|
||||
|
||||
# Update only specific fields
|
||||
updated_var_data["price_money"] = {
|
||||
"amount": price_in_cents,
|
||||
"currency": "USD",
|
||||
}
|
||||
variation_data["sku"] = set_number # LEGO set number
|
||||
variation_data["upc"] = set_upc if set_upc else None # Barcode/GTIN
|
||||
updated_var_data["sku"] = set_number # LEGO set number
|
||||
updated_var_data["upc"] = (
|
||||
set_upc if set_upc else None
|
||||
) # Barcode/GTIN
|
||||
|
||||
variation_obj["item_variation_data"] = variation_data
|
||||
updated_var["item_variation_data"] = updated_var_data
|
||||
|
||||
# Update version if exists (required for updates)
|
||||
# Update version (required for updates)
|
||||
if variation_version is not None:
|
||||
variation_obj["version"] = variation_version
|
||||
updated_var["version"] = variation_version
|
||||
|
||||
updated_variations.append(updated_var)
|
||||
variation_found = True
|
||||
else:
|
||||
# Create new variation if none exists
|
||||
variation_obj = {
|
||||
# Keep other variations as-is
|
||||
updated_variations.append(existing_var)
|
||||
|
||||
# If variation wasn't found (shouldn't happen), create new one
|
||||
if not variation_found:
|
||||
new_variation = {
|
||||
"type": "ITEM_VARIATION",
|
||||
"id": "#TEMP_VARIATION_ID",
|
||||
"id": variation_id if variation_id else "#TEMP_VARIATION_ID",
|
||||
"item_variation_data": {
|
||||
"item_id": item_id,
|
||||
"name": "Regular",
|
||||
@@ -322,33 +347,9 @@ async def update_itm(item_id: str, lego_set: dict, item_data: dict = None):
|
||||
"upc": set_upc if set_upc else None,
|
||||
},
|
||||
}
|
||||
|
||||
# Get the full existing item_data and modify only what we need
|
||||
# This preserves ALL existing fields (location settings, tax, etc)
|
||||
existing_item_data = fresh_item.get("item_data", {})
|
||||
|
||||
# Update only the fields we want to change
|
||||
existing_item_data["name"] = pw_name
|
||||
existing_item_data["description"] = f"{set_name} - {set_theme}"
|
||||
existing_item_data["category_id"] = category_id
|
||||
|
||||
# Update only the specific variation, keep all others unchanged
|
||||
existing_variations = existing_item_data.get("variations", [])
|
||||
updated_variations = []
|
||||
variation_found = False
|
||||
|
||||
for existing_var in existing_variations:
|
||||
if existing_var.get("id") == variation_id:
|
||||
# Replace this variation with our updated one
|
||||
updated_variations.append(variation_obj)
|
||||
variation_found = True
|
||||
else:
|
||||
# Keep other variations as-is
|
||||
updated_variations.append(existing_var)
|
||||
|
||||
# If variation wasn't found (shouldn't happen), add it
|
||||
if not variation_found and variation_id:
|
||||
updated_variations.append(variation_obj)
|
||||
if variation_version is not None:
|
||||
new_variation["version"] = variation_version
|
||||
updated_variations.append(new_variation)
|
||||
|
||||
existing_item_data["variations"] = updated_variations
|
||||
|
||||
|
||||
Reference in new issue
Block a user