|
@@ -69,6 +69,7 @@ serve(wrapHandler('woocommerce-scheduled-sync', async (req) => {
|
|
|
)
|
|
)
|
|
|
`)
|
|
`)
|
|
|
.eq('platform_name', 'woocommerce')
|
|
.eq('platform_name', 'woocommerce')
|
|
|
|
|
+ .eq('is_active', true)
|
|
|
|
|
|
|
|
// If specific frequency requested, filter by it
|
|
// If specific frequency requested, filter by it
|
|
|
if (frequency !== 'all') {
|
|
if (frequency !== 'all') {
|
|
@@ -85,21 +86,37 @@ serve(wrapHandler('woocommerce-scheduled-sync', async (req) => {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ console.log(`[WooCommerce Scheduled Sync] Fetched ${stores?.length || 0} WooCommerce stores from database`)
|
|
|
|
|
+
|
|
|
// Filter stores that have sync enabled and are due for sync
|
|
// Filter stores that have sync enabled and are due for sync
|
|
|
const now = new Date()
|
|
const now = new Date()
|
|
|
const storesToSync = stores?.filter(store => {
|
|
const storesToSync = stores?.filter(store => {
|
|
|
const config = store.store_sync_config?.[0]
|
|
const config = store.store_sync_config?.[0]
|
|
|
|
|
+
|
|
|
|
|
+ // Debug logging
|
|
|
|
|
+ console.log(`[WooCommerce Scheduled Sync] Checking store ${store.id}:`, {
|
|
|
|
|
+ has_config: !!config,
|
|
|
|
|
+ enabled: config?.enabled,
|
|
|
|
|
+ next_sync_at: config?.next_sync_at,
|
|
|
|
|
+ is_array: Array.isArray(store.store_sync_config),
|
|
|
|
|
+ config_length: store.store_sync_config?.length
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
if (!config || !config.enabled) {
|
|
if (!config || !config.enabled) {
|
|
|
|
|
+ console.log(`[WooCommerce Scheduled Sync] Store ${store.id} filtered out: no config or disabled`)
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Check if sync is due
|
|
// Check if sync is due
|
|
|
if (config.next_sync_at) {
|
|
if (config.next_sync_at) {
|
|
|
const nextSync = new Date(config.next_sync_at)
|
|
const nextSync = new Date(config.next_sync_at)
|
|
|
- return nextSync <= now
|
|
|
|
|
|
|
+ const isDue = nextSync <= now
|
|
|
|
|
+ console.log(`[WooCommerce Scheduled Sync] Store ${store.id} next sync: ${config.next_sync_at}, is due: ${isDue}`)
|
|
|
|
|
+ return isDue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// If no next_sync_at, sync is due
|
|
// If no next_sync_at, sync is due
|
|
|
|
|
+ console.log(`[WooCommerce Scheduled Sync] Store ${store.id} has no next_sync_at, sync is due`)
|
|
|
return true
|
|
return true
|
|
|
}) || []
|
|
}) || []
|
|
|
|
|
|