Files
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

57 lines
1.3 KiB
Go

package pricelist
import (
"time"
"github.com/hanzoai/commerce/datastore"
"github.com/hanzoai/commerce/models/mixin"
"github.com/hanzoai/commerce/util/json"
"github.com/hanzoai/orm"
. "github.com/hanzoai/commerce/types"
)
func init() { orm.Register[PriceList]("pricelist") }
type PriceList struct {
mixin.Model[PriceList]
Title string `json:"title"`
Description string `json:"description"`
Status string `json:"status" orm:"default:draft"`
Type string `json:"type"`
StartsAt *time.Time `json:"startsAt,omitempty"`
EndsAt *time.Time `json:"endsAt,omitempty"`
Metadata Map `json:"metadata,omitempty" datastore:"-"`
Metadata_ string `json:"-" datastore:",noindex"`
}
func (p *PriceList) Load(ps []datastore.Property) (err error) {
if err = datastore.LoadStruct(p, ps); err != nil {
return err
}
if len(p.Metadata_) > 0 {
err = json.DecodeBytes([]byte(p.Metadata_), &p.Metadata)
}
return err
}
func (p *PriceList) Save() ([]datastore.Property, error) {
p.Metadata_ = string(json.EncodeBytes(&p.Metadata))
return datastore.SaveStruct(p)
}
func New(db *datastore.Datastore) *PriceList {
t := new(PriceList)
t.Init(db)
return t
}
func Query(db *datastore.Datastore) datastore.Query {
return db.Query("pricelist")
}