From ba79d67ab37b5acaa348112ed5c42d7ad483d195 Mon Sep 17 00:00:00 2001 From: merdan Date: Sun, 25 Sep 2022 22:13:56 +0500 Subject: [PATCH] test --- controllers/ImportController.go | 13 ++++++------- gorm_models/brand.go | 4 ++-- gorm_models/product.go | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/controllers/ImportController.go b/controllers/ImportController.go index de94cec..8cf3f08 100644 --- a/controllers/ImportController.go +++ b/controllers/ImportController.go @@ -211,17 +211,15 @@ func getTotalDocumentCount(db string) int { // todo defailt variant // productflat -func getCats(db *gorm.DB, catIDs []int) ([]gm.Category, string, error) { - var categories []gm.Category +func getCats(db *gorm.DB, catIDs []int) ([3]gm.Category, string, error) { + var categories [3]gm.Category var keywords string - log.Println(catIDs) - if len(mainCategories) > 0 { - for _, id := range catIDs { + for index, id := range catIDs { for _, item := range mainCategories { if item.ID == uint(id) { - categories = append(categories, item) + categories[index] = item break } } @@ -238,6 +236,8 @@ func getCats(db *gorm.DB, catIDs []int) ([]gm.Category, string, error) { } + log.Println(categories) + for _, cat := range categories { if len(cat.Translations) > 0 && cat.Translations[0].MetaKeywords != "" { translation := cat.Translations[0] @@ -246,7 +246,6 @@ func getCats(db *gorm.DB, catIDs []int) ([]gm.Category, string, error) { } } - log.Println(categories) return categories, keywords, nil } diff --git a/gorm_models/brand.go b/gorm_models/brand.go index 7f03085..1fde404 100644 --- a/gorm_models/brand.go +++ b/gorm_models/brand.go @@ -15,10 +15,10 @@ type Brand struct { Name string `gorm:"default:TESTBRAND"` Code string Status bool - Categories []Category `gorm:"many2many:category_brands;"` + Categories [3]Category `gorm:"many2many:category_brands;"` } -func FindOrCreateBrand(db *gorm.DB, brand string, categories []Category) (Brand, error) { +func FindOrCreateBrand(db *gorm.DB, brand string, categories [3]Category) (Brand, error) { var brandObject Brand diff --git a/gorm_models/product.go b/gorm_models/product.go index 1cea3b5..bb3319f 100644 --- a/gorm_models/product.go +++ b/gorm_models/product.go @@ -20,7 +20,7 @@ type Product struct { BrandID uint `sql:"DEFAULT:NULL"` Brand Brand Images []ProductImage - Categories []Category `gorm:"many2many:product_categories;"` + Categories [3]Category `gorm:"many2many:product_categories;"` AttributeValues []ProductAttributeValue SuperAttributes []Attribute `gorm:"many2many:product_super_attributes;"` }