v0.30: product pages, categories, sale prices and order status timeline
This commit is contained in:
+38
-14
@@ -3,17 +3,38 @@ package models
|
||||
import "time"
|
||||
|
||||
type Product struct {
|
||||
ID int
|
||||
Name string
|
||||
Description string
|
||||
Details string
|
||||
Price float64
|
||||
ImageURL string
|
||||
Category string
|
||||
IsActive bool
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Images []ProductImage
|
||||
ID int
|
||||
Name string
|
||||
Description string
|
||||
Details string
|
||||
Price float64
|
||||
SalePrice float64
|
||||
ImageURL string
|
||||
Category string
|
||||
CategoryID *int
|
||||
CategorySlug string
|
||||
IsActive bool
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Images []ProductImage
|
||||
}
|
||||
|
||||
func (p Product) EffectivePrice() float64 {
|
||||
if p.SalePrice > 0 && p.SalePrice < p.Price {
|
||||
return p.SalePrice
|
||||
}
|
||||
return p.Price
|
||||
}
|
||||
|
||||
func (p Product) HasSale() bool {
|
||||
return p.SalePrice > 0 && p.SalePrice < p.Price
|
||||
}
|
||||
|
||||
func (p Product) DiscountPercent() int {
|
||||
if !p.HasSale() || p.Price <= 0 {
|
||||
return 0
|
||||
}
|
||||
return int((1 - p.SalePrice/p.Price) * 100)
|
||||
}
|
||||
|
||||
type ProductImage struct {
|
||||
@@ -26,9 +47,12 @@ type ProductImage struct {
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
Name string
|
||||
Slug string
|
||||
Count int
|
||||
ID int
|
||||
Name string
|
||||
Slug string
|
||||
Description string
|
||||
SortOrder int
|
||||
Count int
|
||||
}
|
||||
|
||||
type SiteStats struct {
|
||||
|
||||
Reference in New Issue
Block a user