fixes
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
@@ -67,10 +66,12 @@ func FillMissingFields(mapped map[string]any, attrs map[string]any) map[string]a
|
||||
}
|
||||
}
|
||||
|
||||
if stringFromAny(out["category"]) == "" {
|
||||
if c := stringFromAny(attrs["category"]); c != "" {
|
||||
out["category"] = c
|
||||
}
|
||||
if c := categoryUniqueIDFromAny(out["category"]); c != "" {
|
||||
out["category"] = c
|
||||
} else if c := categoryUniqueIDFromAny(attrs["category"]); c != "" {
|
||||
out["category"] = c
|
||||
} else if c := categoryUniqueIDFromAny(out["category_unique_id"]); c != "" {
|
||||
out["category"] = c
|
||||
}
|
||||
|
||||
if stringFromAny(out["stock_status"]) == "" {
|
||||
@@ -142,19 +143,7 @@ func normalizeStockStatusLabel(s string) string {
|
||||
}
|
||||
|
||||
func stringFromAny(v any) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
switch t := v.(type) {
|
||||
case string:
|
||||
return strings.TrimSpace(t)
|
||||
case float64, float32, int, int64, bool:
|
||||
s := strings.TrimSpace(fmt.Sprint(t))
|
||||
if s == "<nil>" {
|
||||
return ""
|
||||
}
|
||||
return s
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
// Flatten arrays / #text wrappers; callers that need HTML-stripped descriptions
|
||||
// should use PlainDescriptionFromAny (normalize + V1 enforce do that).
|
||||
return coerceScalarText(v)
|
||||
}
|
||||
Reference in New Issue
Block a user