mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
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
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package shippingoption
|
|
|
|
import (
|
|
"github.com/hanzoai/commerce/datastore"
|
|
"github.com/hanzoai/commerce/models/mixin"
|
|
"github.com/hanzoai/commerce/models/types/currency"
|
|
"github.com/hanzoai/commerce/util/json"
|
|
"github.com/hanzoai/orm"
|
|
|
|
. "github.com/hanzoai/commerce/types"
|
|
)
|
|
|
|
type PriceType string
|
|
|
|
const (
|
|
FlatRate PriceType = "flat"
|
|
Calculated PriceType = "calculated"
|
|
)
|
|
|
|
func init() { orm.Register[ShippingOption]("shippingoption") }
|
|
|
|
type ShippingOption struct {
|
|
mixin.Model[ShippingOption]
|
|
|
|
Name string `json:"name"`
|
|
PriceType PriceType `json:"priceType"`
|
|
Amount currency.Cents `json:"amount"`
|
|
ServiceZoneId string `json:"serviceZoneId"`
|
|
ProviderId string `json:"providerId"`
|
|
ProfileId string `json:"profileId"`
|
|
DataJSON string `json:"data" datastore:",noindex"`
|
|
|
|
Metadata Map `json:"metadata,omitempty" datastore:"-" orm:"default:{}"`
|
|
Metadata_ string `json:"-" datastore:",noindex"`
|
|
}
|
|
|
|
func (s *ShippingOption) Load(ps []datastore.Property) (err error) {
|
|
if err = datastore.LoadStruct(s, ps); err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(s.Metadata_) > 0 {
|
|
err = json.DecodeBytes([]byte(s.Metadata_), &s.Metadata)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (s *ShippingOption) Save() ([]datastore.Property, error) {
|
|
s.Metadata_ = string(json.EncodeBytes(&s.Metadata))
|
|
|
|
return datastore.SaveStruct(s)
|
|
}
|
|
|
|
func New(db *datastore.Datastore) *ShippingOption {
|
|
s := new(ShippingOption)
|
|
s.Init(db)
|
|
return s
|
|
}
|
|
|
|
func Query(db *datastore.Datastore) datastore.Query {
|
|
return db.Query("shippingoption")
|
|
}
|