d
This commit is contained in:
1 parent
94af7d9d89
commit
ce32abf58c
1 file changed
+19
-9
@@ -17,14 +17,18 @@ from pathlib import Path
|
|||||||
# Add parent directory to path for imports
|
# Add parent directory to path for imports
|
||||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||||
|
|
||||||
from asquare import AsyncSquare, get_square_client
|
import get_sq_env
|
||||||
from get_sq_env import SQUARE_LEGO_CAT_ID
|
from square import AsyncSquare
|
||||||
|
|
||||||
|
SQUARE_LEGO_CAT_ID = get_sq_env.LEGO_CAT_ID
|
||||||
|
|
||||||
|
|
||||||
async def migrate_sku_to_gtin():
|
async def migrate_sku_to_gtin():
|
||||||
"""Migrate SKU values to GTIN for all LEGO items."""
|
"""Migrate SKU values to GTIN for all LEGO items."""
|
||||||
client = await get_square_client()
|
client = AsyncSquare(
|
||||||
asquare = AsyncSquare()
|
access_token=get_sq_env.SQUARE_TOKEN,
|
||||||
|
environment=get_sq_env.environment,
|
||||||
|
)
|
||||||
|
|
||||||
print(f"[@INFO] Searching for items in LEGO category {SQUARE_LEGO_CAT_ID}...")
|
print(f"[@INFO] Searching for items in LEGO category {SQUARE_LEGO_CAT_ID}...")
|
||||||
|
|
||||||
@@ -97,15 +101,21 @@ async def migrate_sku_to_gtin():
|
|||||||
"item_variation_data": {
|
"item_variation_data": {
|
||||||
"item_id": item_id,
|
"item_id": item_id,
|
||||||
"name": var_data.get("name", "Regular"),
|
"name": var_data.get("name", "Regular"),
|
||||||
"pricing_type": var_data.get("pricing_type", "FIXED_PRICING"),
|
"pricing_type": var_data.get(
|
||||||
|
"pricing_type", "FIXED_PRICING"
|
||||||
|
),
|
||||||
"upc": sku, # Move SKU value to UPC
|
"upc": sku, # Move SKU value to UPC
|
||||||
"sku": set_number if set_number else None, # Set to LEGO set number if available
|
"sku": (
|
||||||
}
|
set_number if set_number else None
|
||||||
|
), # Set to LEGO set number if available
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# Preserve pricing info
|
# Preserve pricing info
|
||||||
if "price_money" in var_data:
|
if "price_money" in var_data:
|
||||||
updated_var["item_variation_data"]["price_money"] = var_data["price_money"]
|
updated_var["item_variation_data"]["price_money"] = var_data[
|
||||||
|
"price_money"
|
||||||
|
]
|
||||||
|
|
||||||
updated_variations.append(updated_var)
|
updated_variations.append(updated_var)
|
||||||
needs_update = True
|
needs_update = True
|
||||||
@@ -136,7 +146,7 @@ async def migrate_sku_to_gtin():
|
|||||||
"id": item_id,
|
"id": item_id,
|
||||||
"version": fresh_version,
|
"version": fresh_version,
|
||||||
"item_data": fresh_item_data,
|
"item_data": fresh_item_data,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
await client.catalog.object.upsert(body=upsert_body)
|
await client.catalog.object.upsert(body=upsert_body)
|
||||||
|
|||||||
Reference in new issue
Block a user