49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package bagisto_models
|
|
|
|
import (
|
|
"log"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type CategoryTranslation struct {
|
|
ID uint `gorm:"primaryKey"`
|
|
Slug string
|
|
CategoryID uint
|
|
MetaDescription string
|
|
MetaKeywords string
|
|
Locale string
|
|
}
|
|
|
|
type Category struct {
|
|
ID uint `gorm:"primaryKey"`
|
|
Status int8
|
|
Position int
|
|
ParentId uint
|
|
DisplayMode string
|
|
Translations []CategoryTranslation
|
|
}
|
|
|
|
func GetMainCategories(db *gorm.DB) ([]Category, error) {
|
|
var categories []Category
|
|
err := db.Model(&Category{}).Preload("Translations").Find(&categories, "status=1 AND parent_id=1 AND display_mode!='promotion'").Error
|
|
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
return nil, err
|
|
}
|
|
|
|
return categories, nil
|
|
}
|
|
|
|
func GetCatKeywords(db *gorm.DB, catIDs []int) ([]Category, error) {
|
|
var categories []Category
|
|
|
|
if errCat := db.Preload("Translations", "locale=?", "tm").Find(&categories, catIDs).Error; errCat != nil {
|
|
log.Println(errCat)
|
|
return categories, errCat
|
|
}
|
|
|
|
return categories, nil
|
|
}
|