perf: filter by BC category before fetching instead of per-product lookups

When wbc_category_filter is set, sync now pages through BC's /items
endpoint filtered server-side by itemCategoryCode (or-chained eq - BC's
classic OData rejects the `in` operator) and matches each returned item to
a WooCommerce product locally via wc_get_product_id_by_sku(), instead of
querying BC once per WooCommerce product only to discard most of them.
Confirmed against live data that BC's `in` filter isn't supported here but
chained `eq ... or ...` is.

Also reorders find_bc_item_by_sku() to try GTIN/number before Item
Reference (ReferenciasArticulo). Empirically, on this catalog Reference_No
is always identical to Item_No, so the reference lookup never matched
anything the GTIN/number checks didn't already find - it was costing an
extra BC round trip on every single product for no benefit. Kept as a
last-resort fallback both directions (SKU->item and item->SKU) in case
that doesn't hold for some future item.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-09 14:30:51 +02:00
parent 8e093f4c76
commit 0a08086272
3 changed files with 315 additions and 31 deletions

View File

@@ -161,7 +161,10 @@
var run = response.data;
if (run.status === 'running') {
$status.text('Syncing... ' + (run.batches_done || 0) + ' / ' + (run.total_batches || 0) + ' batches (success: ' + (run.success || 0) + ', failed: ' + (run.failed || 0) + ', skipped: ' + (run.skipped || 0) + ')');
var progressText = (run.mode === 'category')
? (run.pages_done || 0) + ' page(s), ' + (run.total || 0) + ' item(s) checked'
: (run.batches_done || 0) + ' / ' + (run.total_batches || 0) + ' batches';
$status.text('Syncing... ' + progressText + ' (success: ' + (run.success || 0) + ', failed: ' + (run.failed || 0) + ', skipped: ' + (run.skipped || 0) + ')');
setTimeout(function() {
WBC_Admin.pollSyncStatus($btn, $status);
}, 3000);