Jelajahi Sumber

feat: update sync functions to populate normalized product fields #111

- ShopRenter: now populates name, sku, price, currency, categories, inner_id
- Shopify: now populates name (from title), sku, price, currency, categories
- Shopify categories derived from product_type
- WooCommerce already had proper field mapping
Claude 4 bulan lalu
induk
melakukan
9f4470a923

+ 15 - 12
supabase/functions/shopify-sync/index.ts

@@ -559,24 +559,27 @@ async function syncProducts(
     const productsToCache = products.map((product: ShopifyProduct) => {
     const productsToCache = products.map((product: ShopifyProduct) => {
       const primaryVariant = product.variants?.[0]
       const primaryVariant = product.variants?.[0]
 
 
+      // Build categories array from product_type and vendor
+      const categories: any[] = []
+      if (product.product_type) {
+        categories.push({
+          id: product.product_type.toLowerCase().replace(/\s+/g, '-'),
+          name: product.product_type
+        })
+      }
+
       return {
       return {
         store_id: storeId,
         store_id: storeId,
         shopify_product_id: product.id.toString(),
         shopify_product_id: product.id.toString(),
-        title: product.title,
-        handle: product.handle,
-        vendor: product.vendor || null,
-        product_type: product.product_type || null,
-        status: product.status,
+        name: product.title, // Map title to name for consistency
+        sku: primaryVariant?.sku || null,
         price: primaryVariant ? parseFloat(primaryVariant.price) : 0,
         price: primaryVariant ? parseFloat(primaryVariant.price) : 0,
-        compare_at_price: primaryVariant?.compare_at_price ? parseFloat(primaryVariant.compare_at_price) : null,
         currency: currency,
         currency: currency,
-        sku: primaryVariant?.sku || null,
-        inventory_quantity: primaryVariant?.inventory_quantity || 0,
-        description: product.body_html || null,
-        images: product.images || [],
-        variants: product.variants || [],
-        options: product.options || [],
+        categories: categories,
+        product_type: product.product_type || null,
+        vendor: product.vendor || null,
         tags: product.tags ? product.tags.split(',').map(t => t.trim()) : [],
         tags: product.tags ? product.tags.split(',').map(t => t.trim()) : [],
+        description: product.body_html || null,
         raw_data: product,
         raw_data: product,
         last_synced_at: new Date().toISOString()
         last_synced_at: new Date().toISOString()
       }
       }

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

@@ -944,6 +944,12 @@ serve(wrapHandler('shoprenter-sync', async (req) => {
             const productsToCache = productsData.items.map((product: any) => ({
             const productsToCache = productsData.items.map((product: any) => ({
               store_id: storeId,
               store_id: storeId,
               shoprenter_product_id: product.id,
               shoprenter_product_id: product.id,
+              inner_id: product.innerId,
+              name: product.name,
+              sku: product.sku,
+              price: product.price,
+              currency: product.currency || 'HUF',
+              categories: product.productCategory || [],
               product_data: product,
               product_data: product,
               last_synced_at: new Date().toISOString()
               last_synced_at: new Date().toISOString()
             }))
             }))