Wird jetzt nach kategorien die Seiten angezeigt
This commit is contained in:
@@ -7,15 +7,17 @@ import (
|
||||
)
|
||||
|
||||
type Product struct {
|
||||
ID string `gorm:"size:36;not null;uniqueIndex;primary_key"`
|
||||
ParentID string `gorm:"size:36;index"`
|
||||
Name string `gorm:"size:255"`
|
||||
Slug string `gorm:"size:255"`
|
||||
ProductImages []ProductImage
|
||||
Price decimal.Decimal `gorm:"type:decimal(16,2);"`
|
||||
Categories []Category `gorm:"many2many:product_categories;"`
|
||||
ShortDescription string `gorm:"type:text"`
|
||||
Description string `gorm:"type:text"`
|
||||
ID string `gorm:"size:36;not null;uniqueIndex;primary_key"`
|
||||
ParentID string `gorm:"size:36;index"`
|
||||
Name string `gorm:"size:255"`
|
||||
Slug string `gorm:"size:255"`
|
||||
ProductImages []ProductImage
|
||||
Price decimal.Decimal `gorm:"type:decimal(16,2);"`
|
||||
//Categories []Category `gorm:"many2many:product_categories;"`
|
||||
Category Category
|
||||
CategoryID string
|
||||
ShortDescription string `gorm:"type:text"`
|
||||
Description string `gorm:"type:text"`
|
||||
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
@@ -41,6 +43,19 @@ func (p *Product) GetProducts(db *gorm.DB, perPage int, page int) (*[]Product, i
|
||||
return &products, count, nil
|
||||
}
|
||||
|
||||
func (p *Product) GetProductsByCategory(db *gorm.DB, categoryID string) (*[]Product, int64, error) {
|
||||
var count int64
|
||||
var products []Product
|
||||
|
||||
err := db.Debug().Model(&Product{}).Order("created_at desc").Where("category_id = ?", categoryID).Find(&products).Count(&count).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return &products, count, nil
|
||||
|
||||
}
|
||||
|
||||
func (p *Product) FindByID(db *gorm.DB, productID string) (*Product, error) {
|
||||
var err error
|
||||
var product Product
|
||||
|
||||
Reference in New Issue
Block a user