Quellcode durchsuchen

fix: Add phone number fields to WooCommerce cache tables #30

- Created database migration to add phone fields
- Added phone column to woocommerce_customers_cache table
- Added customer_phone column to woocommerce_orders_cache table
- Updated woocommerce-sync function to extract phone numbers from billing data
- Added indexes for phone number lookups

Extracts phone numbers from:
- customer.billing.phone for customers
- order.billing.phone for orders

Related: #29 (parent issue - customers phone number)

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

Co-Authored-By: Claude <noreply@anthropic.com>
Claude vor 5 Monaten
Ursprung
Commit
81a33b12f8

+ 2 - 0
supabase/functions/woocommerce-sync/index.ts

@@ -178,6 +178,7 @@ async function syncOrders(
         currency: order.currency || 'USD',
         currency: order.currency || 'USD',
         customer_name: `${order.billing?.first_name || ''} ${order.billing?.last_name || ''}`.trim(),
         customer_name: `${order.billing?.first_name || ''} ${order.billing?.last_name || ''}`.trim(),
         customer_email: order.billing?.email || null,
         customer_email: order.billing?.email || null,
+        customer_phone: order.billing?.phone || null,
         line_items: order.line_items || [],
         line_items: order.line_items || [],
         billing_address: order.billing || null,
         billing_address: order.billing || null,
         shipping_address: order.shipping || null,
         shipping_address: order.shipping || null,
@@ -249,6 +250,7 @@ async function syncCustomers(
         first_name: customer.first_name || null,
         first_name: customer.first_name || null,
         last_name: customer.last_name || null,
         last_name: customer.last_name || null,
         username: customer.username || null,
         username: customer.username || null,
+        phone: customer.billing?.phone || null,
         billing_address: customer.billing || null,
         billing_address: customer.billing || null,
         shipping_address: customer.shipping || null,
         shipping_address: customer.shipping || null,
         orders_count: customer.orders_count || 0,
         orders_count: customer.orders_count || 0,

+ 44 - 0
supabase/migrations/20251031_add_woocommerce_phone_fields.sql

@@ -0,0 +1,44 @@
+-- Migration: Add phone number fields to WooCommerce cache tables
+-- Description: Adds phone fields to customers and orders cache for contact information
+-- Date: 2025-10-31
+-- Related Issue: #30
+
+-- ============================================================================
+-- STEP 1: Add phone field to woocommerce_customers_cache
+-- ============================================================================
+
+ALTER TABLE woocommerce_customers_cache
+ADD COLUMN IF NOT EXISTS phone TEXT;
+
+-- Add index for phone number lookups
+CREATE INDEX IF NOT EXISTS idx_wc_customers_phone
+  ON woocommerce_customers_cache(store_id, phone)
+  WHERE phone IS NOT NULL;
+
+-- ============================================================================
+-- STEP 2: Add customer_phone field to woocommerce_orders_cache
+-- ============================================================================
+
+ALTER TABLE woocommerce_orders_cache
+ADD COLUMN IF NOT EXISTS customer_phone TEXT;
+
+-- Add index for phone number lookups
+CREATE INDEX IF NOT EXISTS idx_wc_orders_customer_phone
+  ON woocommerce_orders_cache(store_id, customer_phone)
+  WHERE customer_phone IS NOT NULL;
+
+-- ============================================================================
+-- Migration Complete
+-- ============================================================================
+
+DO $$
+BEGIN
+  RAISE NOTICE 'WooCommerce phone fields migration completed successfully';
+  RAISE NOTICE 'Added columns:';
+  RAISE NOTICE '  - woocommerce_customers_cache.phone';
+  RAISE NOTICE '  - woocommerce_orders_cache.customer_phone';
+  RAISE NOTICE '';
+  RAISE NOTICE 'Next steps:';
+  RAISE NOTICE '1. Deploy updated woocommerce-sync Edge Function';
+  RAISE NOTICE '2. Re-sync WooCommerce stores to populate phone numbers';
+END $$;