This commit is contained in:
greeneclipse committed 2026-10-20 17:19:46 +02:00
1 parent 1c003e30a4
commit c83347b9a5
2 files changed
+41 -3

No files matched your search

+10 -3
View File
@@ -37,7 +37,7 @@ func headerIndex(headers []string, names ...string) int {
want[strings.ToLower(strings.TrimSpace(n))] = struct{}{}
}
for i, h := range headers {
if _, ok := want[strings.ToLower(strings.TrimSpace(h))]; ok {
if _, ok := want[strings.ToLower(strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(h), "\uFEFF")))]; ok {
return i
}
}
@@ -509,6 +509,13 @@ func (s *Service) MergeProductsByGTIN(ctx context.Context, companyID uuid.UUID)
return merge, err
}
// shouldMergeProductCSV reuses an existing GTIN for regular merge-enabled feeds
// and for non-primary-language imports, which add localizations to the same product.
// Generated no-GTIN identifiers must always create separate products.
func shouldMergeProductCSV(allowMerge, isPrimary bool, gtin string) bool {
return (allowMerge || !isPrimary) && !strings.HasPrefix(gtin, "nogtin-")
}
type productCSVRow struct {
gtin, productID, name, category, desc, status string
rawJSON string
@@ -517,7 +524,7 @@ type productCSVRow struct {
func (s *Service) ImportProductsCSV(ctx context.Context, companyID uuid.UUID, r io.Reader, fileID *uuid.UUID) (ImportResult, error) {
res := ImportResult{}
lang, primary := s.importLanguage(ctx, companyID)
_, primary := s.importLanguage(ctx, companyID)
merge, err := s.MergeProductsByGTIN(ctx, companyID)
if err != nil {
return res, err
@@ -576,7 +583,7 @@ func (s *Service) ImportProductsCSV(ctx context.Context, companyID uuid.UUID, r
batch = append(batch, productCSVRow{
gtin: gtin, productID: productID, name: name, category: category,
desc: desc, status: status, rawJSON: string(rawData),
mergeable: (merge || lang != primary) && !strings.HasPrefix(gtin, "nogtin-"),
mergeable: shouldMergeProductCSV(merge, primary, gtin),
})
if len(batch) >= importCSVBatchSize {
if err := s.flushProductBatch(ctx, companyID, fileID, batch, &res); err != nil {