This commit is contained in:
2026-08-16 17:16:47 +02:00
parent 532d439c41
commit d161b28a10
5 changed files with 170 additions and 21 deletions
+21 -3
View File
@@ -1462,6 +1462,17 @@ func (p *Pipeline) processOne(ctx context.Context, companyID, jobID uuid.UUID, i
if cat := categoryUniqueIDFromMaps(enriched, raw); cat != "" {
enriched["category"] = cat
}
// Resolve display names → taxonomy unique_id before RunSteps so category
// formulas, enhance overlays, and attribute allowlists key correctly.
if cache != nil {
if resolved := resolveCompanyCategoryUniqueID(
stringFromAny(enriched["category"]),
cache.categoryNamesByUID,
cache.categoryUniqueIDs,
); resolved != "" {
enriched["category"] = resolved
}
}
if gtin == "" {
gtin = stringFromMap(enriched, "gtin", "ean", "EAN", "upc")
}
@@ -1528,8 +1539,10 @@ func (p *Pipeline) processOne(ctx context.Context, companyID, jobID uuid.UUID, i
return false, 0, StepResult{}, err
}
// Persist mapped unique_id only when it exists in the company taxonomy.
// Empty taxonomy set skips filtering (unit tests / companies without categories).
// Coerce display names (feed/vector) → unique_id before filtering so A1-style
// name tokens are not wiped. Empty taxonomy set skips filtering (unit tests).
if cache != nil {
coerceCategoryToCompanyUniqueID(&result, cache.categoryNamesByUID, cache.categoryUniqueIDs)
filterCategoryIfInvalid(&result, cache.categoryUniqueIDs)
syncCategoryName(&result, cache.categoryNamesByUID)
}
@@ -1577,7 +1590,7 @@ func (p *Pipeline) processOne(ctx context.Context, companyID, jobID uuid.UUID, i
cache.noteCreditDebit(p.Billing.EstimateDebit(ctx, "product_processing", result.TotalTokens))
}
processedID, err := p.upsertProcessedProduct(ctx, tx, companyID, it.RawID, gtin, result, attrsJSON, procAttrsJSON, gptJSON, sourcesJSON, providerMode)
processedID, err := p.upsertProcessedProduct(ctx, tx, companyID, it.RawID, gtin, result, attrsJSON, procAttrsJSON, gptJSON, sourcesJSON, providerMode, language)
if err != nil {
return false, 0, result, err
}
@@ -1705,13 +1718,18 @@ func (p *Pipeline) upsertProcessedProduct(
result StepResult,
attrsJSON, procAttrsJSON, gptJSON, sourcesJSON []byte,
providerMode string,
primaryLang string,
) (uuid.UUID, error) {
localized := result.LocalizedContent
if localized == nil {
localized = company.LocalizedContent{}
}
if len(localized) == 0 && (strings.TrimSpace(result.ProcessedName) != "" || strings.TrimSpace(result.ProcessedDescription) != "") {
localized[company.DefaultLanguage] = company.LocalizedFields{
lang := company.NormalizeLanguage(primaryLang)
if lang == "" || lang == company.LangPromptAny || !company.IsAllowedLanguage(lang) {
lang = company.DefaultLanguage
}
localized[lang] = company.LocalizedFields{
ProcessedName: result.ProcessedName,
ProcessedDescription: result.ProcessedDescription,
}