Problem: my Node.js sync server logs show successful product updates in WooCommerce (HTTP 200 responses), but when checking the WooCommerce admin panel:
- Some price/name changes aren't actually saved
- Some products are created and then saved differently?
- Products occasionally revert to previous states
- No errors are logged despite the changes not persisting
Evidence from logs:
2025-04-04T08:57:53.552Z [INFO]: Updated product O-GOSGP6XXZ05 (ID: 58597)
2025-04-04T08:57:54.018Z [DEBUG]: Updated product: Netzbuchsen Lötarbeiten (ID: 62082)
2025-04-04T08:57:54.871Z [INFO]: Updated product O-MOSMGXXXG4 (ID: 31218)
2025-04-04T08:57:55.391Z [DEBUG]: Updated product: Austausch Display-LCD/LED-Einheit (ID: 30612)
But these changes don't appear in WooCommerce's admin UI.
Current sync flow:
- Fetch products from MySQL
- Compare with WooCommerce products
- Batch updates via WooCommerce REST API
- Log successful updates
Here's the part of the codes that correspond to the syncing process:
Core synchronization logic (from syncService.js):
async function syncProducts() {
try {
// 1. Fetch products from both sources
const sqlProducts = await fetchProducts(); // From SQL
const wooProducts = await fetchWooCommerceProducts(); // From WooCommerce
// 2. Compare products
const { newProducts, updatedProducts } = compareProducts(sqlProducts, wooProducts);
// 3. Process new products
for (const product of newProducts) {
await createWooCommerceProduct({
name: `${product.device_name} - ${product.repair_type}`,
sku: product.sku,
regular_price: product.price.toString(),
stock_quantity: 10
});
}
// 4. Process updates
for (const product of updatedProducts) {
await updateWooCommerceProduct(product.wooId, {
name: product.repair_type,
regular_price: product.price.toString()
});
}
} catch (err) {
logger.error('Sync failed', {
error: err.message,
response: err.response?.data
});
}
}
WooCommerce API client (from wooService.js):
const wooCommerce = axios.create({
baseURL: `${process.env.WOOCOMMERCE_URL}/wp-json/wc/v3`,
auth: {
username: process.env.WOOCOMMERCE_CONSUMER_KEY,
password: process.env.WOOCOMMERCE_CONSUMER_SECRET
}
});
// Rate limited to 90 requests/minute
const limiter = new Bottleneck({
minTime: 60000 / 90
});
async function updateWooCommerceProduct(productId, product) {
const response = await limiter.schedule(() =>
wooCommerce.put(`/products/${productId}`, product)
);
return response.data;
}
Tried looking at the SKU format to check if it fits out existing WooCommerce format. Seemed fine, also checked the logic of the comparison between SKUs.... nothing was wrong, it detected the updated devices as well as the new ones easily. I was expecting a simple way of comparing the products, then just the code just using a simple 'PUT' Request with the new data to the SKU....
Network tabondeveloper tools?