refactor(price): remove price comparison UI and catalog sync
GoMag vs ROA price comparison generated too many false positives (kits, volume discounts, special prices). Removes comparison columns, dots, badges, catalog sync endpoints, and ~950 lines of dead code. Keeps WRITE path (sync_prices_from_order) for kit pricing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -103,80 +103,3 @@ async def download_orders(
|
||||
return {"pages": total_pages, "total": total_orders, "files": saved_files}
|
||||
|
||||
|
||||
async def download_products(
|
||||
api_key: str = None,
|
||||
api_shop: str = None,
|
||||
products_url: str = None,
|
||||
log_fn: Callable[[str], None] = None,
|
||||
) -> list[dict]:
|
||||
"""Download all products from GoMag Products API.
|
||||
Returns list of product dicts with: sku, price, vat, vat_included, bundleItems.
|
||||
"""
|
||||
def _log(msg: str):
|
||||
logger.info(msg)
|
||||
if log_fn:
|
||||
log_fn(msg)
|
||||
|
||||
effective_key = api_key or settings.GOMAG_API_KEY
|
||||
effective_shop = api_shop or settings.GOMAG_API_SHOP
|
||||
default_url = "https://api.gomag.ro/api/v1/product/read/json"
|
||||
effective_url = products_url or default_url
|
||||
|
||||
if not effective_key or not effective_shop:
|
||||
_log("GoMag API keys neconfigurați, skip product download")
|
||||
return []
|
||||
|
||||
headers = {
|
||||
"Apikey": effective_key,
|
||||
"ApiShop": effective_shop,
|
||||
"User-Agent": "Mozilla/5.0",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
all_products = []
|
||||
total_pages = 1
|
||||
|
||||
async with httpx.AsyncClient(timeout=30) as client:
|
||||
page = 1
|
||||
while page <= total_pages:
|
||||
params = {"page": page, "limit": 100}
|
||||
try:
|
||||
response = await client.get(effective_url, headers=headers, params=params)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except httpx.HTTPError as e:
|
||||
_log(f"GoMag Products API eroare pagina {page}: {e}")
|
||||
break
|
||||
except Exception as e:
|
||||
_log(f"GoMag Products eroare neașteptată pagina {page}: {e}")
|
||||
break
|
||||
|
||||
if page == 1:
|
||||
total_pages = int(data.get("pages", 1))
|
||||
_log(f"GoMag Products: {data.get('total', '?')} produse în {total_pages} pagini")
|
||||
|
||||
products = data.get("products", [])
|
||||
if isinstance(products, dict):
|
||||
# GoMag returns products as {"1": {...}, "2": {...}} dict
|
||||
first_val = next(iter(products.values()), None) if products else None
|
||||
if isinstance(first_val, dict):
|
||||
products = list(products.values())
|
||||
else:
|
||||
products = [products]
|
||||
if isinstance(products, list):
|
||||
for p in products:
|
||||
if isinstance(p, dict) and p.get("sku"):
|
||||
all_products.append({
|
||||
"sku": p["sku"],
|
||||
"price": p.get("price", "0"),
|
||||
"vat": p.get("vat", "19"),
|
||||
"vat_included": str(p.get("vat_included", "1")),
|
||||
"bundleItems": p.get("bundleItems", []),
|
||||
})
|
||||
|
||||
page += 1
|
||||
if page <= total_pages:
|
||||
await asyncio.sleep(1)
|
||||
|
||||
_log(f"GoMag Products: {len(all_products)} produse cu SKU descărcate")
|
||||
return all_products
|
||||
|
||||
Reference in New Issue
Block a user