Browse Source

fix: use innerId instead of id for ShopRenter products in Qdrant #81

Changes:
- Updated shoprenter-sync to use product.innerId for Qdrant point IDs
- Changed product_id payload to store innerId instead of base64-encoded API ID
- Updated adaptShopRenterProduct to use innerId as primary ID with fallback
- Products now stored with correct numeric IDs (e.g., "1707") instead of API request IDs

Fixes issue where Qdrant stored products with base64-encoded API request IDs
instead of the actual innerId values from the ShopRenter API response.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Claude 5 months ago
parent
commit
00a6af649c

+ 1 - 1
supabase/functions/_shared/platform-adapters.ts

@@ -436,7 +436,7 @@ export function adaptShopRenterLineItem(srItem: any): UnifiedLineItem {
 
 
 export function adaptShopRenterProduct(srProduct: any): UnifiedProduct {
 export function adaptShopRenterProduct(srProduct: any): UnifiedProduct {
   return {
   return {
-    id: String(srProduct.id),
+    id: String(srProduct.innerId || srProduct.id),
     platform: "shoprenter",
     platform: "shoprenter",
     title: srProduct.name || "Untitled Product",
     title: srProduct.name || "Untitled Product",
     description: srProduct.description || null,
     description: srProduct.description || null,

+ 6 - 6
supabase/functions/shoprenter-sync/index.ts

@@ -67,11 +67,11 @@ async function syncProductsToQdrant(
   const startTime = new Date()
   const startTime = new Date()
   const collectionName = getCollectionName(storeName, 'products')
   const collectionName = getCollectionName(storeName, 'products')
 
 
-  // Filter out products without valid IDs
-  const validProducts = products.filter(p => p && p.id)
+  // Filter out products without valid IDs (must have innerId)
+  const validProducts = products.filter(p => p && p.innerId)
 
 
   if (validProducts.length === 0) {
   if (validProducts.length === 0) {
-    console.log('[Qdrant] No valid products to sync (all products missing IDs)')
+    console.log('[Qdrant] No valid products to sync (all products missing innerId)')
     return { synced: 0, errors: 0 }
     return { synced: 0, errors: 0 }
   }
   }
 
 
@@ -101,7 +101,7 @@ async function syncProductsToQdrant(
       existingPoints.points.map((p: any) => p.payload?.product_id).filter(Boolean)
       existingPoints.points.map((p: any) => p.payload?.product_id).filter(Boolean)
     )
     )
 
 
-    const currentProductIds = new Set(validProducts.map(p => p.id.toString()))
+    const currentProductIds = new Set(validProducts.map(p => p.innerId.toString()))
 
 
     // Find deleted products
     // Find deleted products
     const deletedProductIds = Array.from(existingProductIds).filter(
     const deletedProductIds = Array.from(existingProductIds).filter(
@@ -141,12 +141,12 @@ async function syncProductsToQdrant(
 
 
     // Convert products to Qdrant points with embeddings and comprehensive details
     // Convert products to Qdrant points with embeddings and comprehensive details
     const points: QdrantPoint[] = validProducts.map((product, index) => ({
     const points: QdrantPoint[] = validProducts.map((product, index) => ({
-      id: generatePointId('shoprenter', storeId, product.id),
+      id: generatePointId('shoprenter', storeId, product.innerId),
       vector: embeddings[index],
       vector: embeddings[index],
       payload: {
       payload: {
         // Basic identification
         // Basic identification
         store_id: storeId,
         store_id: storeId,
-        product_id: product.id.toString(),
+        product_id: product.innerId.toString(),
         platform: 'shoprenter',
         platform: 'shoprenter',
         name: product.name,
         name: product.name,
         sku: product.sku || null,
         sku: product.sku || null,