diff --git a/src/modules/3-turn-engine/stateHandlers.js b/src/modules/3-turn-engine/stateHandlers.js index 3078bb2..9513e34 100644 --- a/src/modules/3-turn-engine/stateHandlers.js +++ b/src/modules/3-turn-engine/stateHandlers.js @@ -746,7 +746,8 @@ function createPendingItemFromSearch({ query, quantity, unit, candidates }) { (best?._score >= 0.9 && (!second || best._score - (second?._score || 0) >= 0.2)); if (isStrong) { - const displayUnit = inferDefaultUnit({ name: best.name, categories: best.categories }); + // Usar sell_unit del producto si está configurado, sino inferir por heurística + const displayUnit = normalizeUnit(best.sell_unit) || inferDefaultUnit({ name: best.name, categories: best.categories }); const hasQty = quantity != null && Number.isFinite(Number(quantity)) && Number(quantity) > 0; const sellsByWeight = displayUnit !== "unit"; const hasExplicitUnit = unit != null && unit !== ""; @@ -773,7 +774,8 @@ function createPendingItemFromSearch({ query, quantity, unit, candidates }) { woo_id: c.woo_product_id, name: c.name, price: c.price, - display_unit: inferDefaultUnit({ name: c.name, categories: c.categories }), + sell_unit: c.sell_unit || null, + display_unit: normalizeUnit(c.sell_unit) || inferDefaultUnit({ name: c.name, categories: c.categories }), })), status: PendingStatus.NEEDS_TYPE, }); diff --git a/src/modules/shared/wooSnapshot.js b/src/modules/shared/wooSnapshot.js index 73a2fd1..cc2f064 100644 --- a/src/modules/shared/wooSnapshot.js +++ b/src/modules/shared/wooSnapshot.js @@ -133,6 +133,7 @@ function snapshotRowToItem(row) { sale_price: row?.price_sale ?? null, price_html: null, }, + sell_unit: raw?._sell_unit_override || null, source: "snapshot", }; }