diff --git a/backend/queue_worker.py b/backend/queue_worker.py index 8a56946..f42e76e 100644 --- a/backend/queue_worker.py +++ b/backend/queue_worker.py @@ -179,25 +179,37 @@ class QueueWorker: if products: log.info(f"Fallback başarılı: {len(products)} ürün bulundu (cat_id={cat_id})") - # Enrich with socialProofs from Top Rankings API - if products and cat_id and not any(p.get("socialProofs") for p in products): + # Enrich barcode, origin (winnerVariant/merchantListings) and socialProofs + # from Top Rankings API. Search API returns empty winnerVariant/merchantListings, + # so barcode and country-of-origin data is missing without this step. + if products and cat_id and not any(p.get("winnerVariant") for p in products): try: _trendyol_limiter.wait() top_scraper = TrendyolScraper(cat_id, page_size=20) top_products = top_scraper.fetch_all_products(delay=0.5, max_pages=5) if top_products: - social_map = {} + top_map = {} for tp in top_products: tid = tp.get("id") or tp.get("contentId") - sp = tp.get("socialProofs", []) - if tid and sp: - social_map[int(tid)] = sp - if social_map: - for p in products: - pid = p.get("id") - if pid and int(pid) in social_map: - p["socialProofs"] = social_map[int(pid)] - log.info(f"Enriched {len(social_map)} products with socialProofs") + if tid: + top_map[int(tid)] = tp + enriched = 0 + for p in products: + pid = p.get("id") + if pid and int(pid) in top_map: + tp = top_map[int(pid)] + wv = tp.get("winnerVariant") or {} + ml = tp.get("merchantListings") or [] + sp = tp.get("socialProofs") or [] + if wv: + p["winnerVariant"] = wv + if ml: + p["merchantListings"] = ml + if sp and not p.get("socialProofs"): + p["socialProofs"] = sp + enriched += 1 + if enriched: + log.info(f"Enriched {enriched} products with barcode/origin/socialProofs from Top Rankings") except Exception as e: log.warning(f"Top Rankings enrichment failed: {e}")