fdsadsa
This commit is contained in:
1 parent
bcb4e65585
commit
0089ce8556
1 file changed
+49
-47
+49
-47
@@ -249,59 +249,61 @@ async def update_itm(item_id: str, lego_set: dict, item_data: dict = None):
|
|||||||
|
|
||||||
variations = fresh_item.get("variations", [])
|
variations = fresh_item.get("variations", [])
|
||||||
|
|
||||||
if not variations:
|
if not variations:
|
||||||
print(
|
print(
|
||||||
f"[@WARNING] Item {item_id} has no variations, creating new variation"
|
f"[@WARNING] Item {item_id} has no variations, creating new variation"
|
||||||
)
|
)
|
||||||
variation_id = None
|
variation_id = None
|
||||||
variation_version = None
|
variation_version = None
|
||||||
else:
|
else:
|
||||||
variation_id = variations[0]["id"]
|
variation_id = variations[0]["id"]
|
||||||
variation_version = variations[0].get("version")
|
variation_version = variations[0].get("version")
|
||||||
|
|
||||||
# Get current version for version control
|
# Get current version for version control
|
||||||
current_version = fresh_item.get("version")
|
current_version = fresh_item.get("version")
|
||||||
|
|
||||||
print(f"[@DEBUG] Fresh item version: {current_version}")
|
print(f"[@DEBUG] Fresh item version: {current_version}")
|
||||||
print(f"[@DEBUG] Fresh variation version: {variation_version}")
|
print(f"[@DEBUG] Fresh variation version: {variation_version}")
|
||||||
|
|
||||||
# Build upsert body
|
# Build upsert body
|
||||||
upsert_body = {
|
upsert_body = {
|
||||||
"idempotency_key": str(uuid.uuid4()),
|
"idempotency_key": str(uuid.uuid4()),
|
||||||
"object": {
|
"object": {
|
||||||
"type": "ITEM",
|
"type": "ITEM",
|
||||||
"id": item_id,
|
"id": item_id,
|
||||||
"version": current_version, # Include version for conflict prevention
|
"version": current_version, # Include version for conflict prevention
|
||||||
"item_data": {
|
"item_data": {
|
||||||
"name": pw_name,
|
"name": pw_name,
|
||||||
"description": f"{set_name} - {set_theme}",
|
"description": f"{set_name} - {set_theme}",
|
||||||
"variations": [
|
"variations": [
|
||||||
{
|
{
|
||||||
"type": "ITEM_VARIATION",
|
"type": "ITEM_VARIATION",
|
||||||
"id": (
|
"id": (
|
||||||
variation_id if variation_id else "#TEMP_VARIATION_ID"
|
variation_id
|
||||||
),
|
if variation_id
|
||||||
"item_variation_data": {
|
else "#TEMP_VARIATION_ID"
|
||||||
"item_id": item_id,
|
),
|
||||||
"name": "Regular",
|
"item_variation_data": {
|
||||||
"pricing_type": "FIXED_PRICING",
|
"item_id": item_id,
|
||||||
"price_money": {
|
"name": "Regular",
|
||||||
"amount": price_in_cents,
|
"pricing_type": "FIXED_PRICING",
|
||||||
"currency": "USD",
|
"price_money": {
|
||||||
|
"amount": price_in_cents,
|
||||||
|
"currency": "USD",
|
||||||
|
},
|
||||||
|
"sku": set_upc if set_upc else None,
|
||||||
},
|
},
|
||||||
"sku": set_upc if set_upc else None,
|
}
|
||||||
},
|
],
|
||||||
}
|
},
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
}
|
|
||||||
|
|
||||||
# Remove None values
|
# Remove None values
|
||||||
if not set_upc:
|
if not set_upc:
|
||||||
del upsert_body["object"]["item_data"]["variations"][0][
|
del upsert_body["object"]["item_data"]["variations"][0][
|
||||||
"item_variation_data"
|
"item_variation_data"
|
||||||
]["sku"]
|
]["sku"]
|
||||||
|
|
||||||
print(f"[@DEBUG] Upserting item {item_id} with name: {pw_name}")
|
print(f"[@DEBUG] Upserting item {item_id} with name: {pw_name}")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user