v0.30: product pages, categories, sale prices and order status timeline

This commit is contained in:
shop
2026-06-25 17:29:43 +03:00
parent 532351e1c9
commit e000264bb1
26 changed files with 1061 additions and 248 deletions
+38 -14
View File
@@ -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 {