|
@@ -941,16 +941,31 @@ serve(wrapHandler('shoprenter-sync', async (req) => {
|
|
|
// Collect all products for Qdrant sync
|
|
// Collect all products for Qdrant sync
|
|
|
allProducts.push(...productsData.items)
|
|
allProducts.push(...productsData.items)
|
|
|
|
|
|
|
|
- const productsToCache = productsData.items.map((product: any) => ({
|
|
|
|
|
- store_id: storeId,
|
|
|
|
|
- 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 productsToCache = productsData.items.map((product: any) => {
|
|
|
|
|
+ // Extract first language description from productDescriptions array
|
|
|
|
|
+ const productDesc = product.productDescriptions?.[0] || {}
|
|
|
|
|
+
|
|
|
|
|
+ // Extract category IDs from productCategoryRelations
|
|
|
|
|
+ const categoryIds: string[] = []
|
|
|
|
|
+ const categoryRelations = product.productCategoryRelations || []
|
|
|
|
|
+ for (const rel of categoryRelations) {
|
|
|
|
|
+ const categoryId = extractCategoryId(rel.category?.href)
|
|
|
|
|
+ if (categoryId) {
|
|
|
|
|
+ categoryIds.push(categoryId)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ store_id: storeId,
|
|
|
|
|
+ product_id: product.id,
|
|
|
|
|
+ inner_id: product.innerId,
|
|
|
|
|
+ name: productDesc.name || product.name || null,
|
|
|
|
|
+ sku: product.sku || null,
|
|
|
|
|
+ categories: categoryIds,
|
|
|
|
|
+ excluded: false, // Will be set if in exclusion list
|
|
|
|
|
+ last_synced_at: new Date().toISOString()
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
const { error: upsertError } = await supabaseAdmin
|
|
const { error: upsertError } = await supabaseAdmin
|
|
|
.from('shoprenter_products_cache')
|
|
.from('shoprenter_products_cache')
|