Browse Source

fix: update shoprenter-scheduled-sync to use new minimal product cache schema #112

- Fixed product_data column error (column removed in schema refactor #111)
- Updated product mapping to use new minimal fields: product_id, inner_id, name, sku, categories
- Fixed onConflict clause to match new unique constraint (store_id,product_id)
- Sync will now work correctly with the refactored shoprenter_products_cache table
Claude 4 months ago
parent
commit
7b15181224
1 changed files with 7 additions and 3 deletions
  1. 7 3
      supabase/functions/shoprenter-scheduled-sync/index.ts

+ 7 - 3
supabase/functions/shoprenter-scheduled-sync/index.ts

@@ -183,15 +183,19 @@ serve(wrapHandler('shoprenter-scheduled-sync', async (req) => {
               if (productsData.items && productsData.items.length > 0) {
                 const productsToCache = productsData.items.map((product: any) => ({
                   store_id: storeId,
-                  shoprenter_product_id: product.id,
-                  product_data: product,
+                  product_id: product.id,
+                  inner_id: product.innerId,
+                  name: product.name,
+                  sku: product.sku,
+                  categories: product.productCategory || [],
+                  excluded: false, // Will be set if in exclusion list
                   last_synced_at: new Date().toISOString()
                 }))
 
                 const { error: upsertError } = await supabaseAdmin
                   .from('shoprenter_products_cache')
                   .upsert(productsToCache, {
-                    onConflict: 'store_id,shoprenter_product_id'
+                    onConflict: 'store_id,product_id'
                   })
 
                 if (upsertError) {