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
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
package bundle
|
|
|
|
import (
|
|
"github.com/hanzoai/commerce/datastore"
|
|
"github.com/hanzoai/commerce/models/mixin"
|
|
"github.com/hanzoai/commerce/util/val"
|
|
"github.com/hanzoai/orm"
|
|
|
|
. "github.com/hanzoai/commerce/types"
|
|
)
|
|
|
|
var IgnoreFieldMismatch = datastore.IgnoreFieldMismatch
|
|
|
|
func init() { orm.Register[Bundle]("bundle") }
|
|
|
|
// A bundle of Products/Variants to be listed on a store
|
|
type Bundle struct {
|
|
mixin.Model[Bundle]
|
|
|
|
// Unique human readable identifier
|
|
Slug string `json:"slug"`
|
|
|
|
// Name of bundle
|
|
Name string `json:"name"`
|
|
|
|
// Description of bundle
|
|
Description string `datastore:",noindex" json:"description"`
|
|
|
|
// Image/Video/Other Media to show in a gallery
|
|
Media []Media `json:"media"`
|
|
|
|
// Is the bundle available
|
|
Available bool `json:"available"`
|
|
|
|
// Is product hidden from users
|
|
Hidden bool `json:"hidden"`
|
|
|
|
// Range in which bundle is available. If active, it takes precedent
|
|
// over Available bool.
|
|
Availability Availability `json:"availability"`
|
|
|
|
// Show this on store?
|
|
Published bool `json:"published"`
|
|
|
|
// Is this a preorder?
|
|
Preorder bool `json:"preorder"`
|
|
|
|
// Lists of products or specific product variants that are part of this
|
|
// bundle
|
|
ProductIds []string `json:"productIds"`
|
|
VariantIds []string `json:"variantIds"`
|
|
}
|
|
|
|
func (c *Bundle) Validator() *val.Validator {
|
|
return val.New().
|
|
Check("Slug").Exists().
|
|
Check("Name").Exists()
|
|
}
|
|
|
|
func (c Bundle) GetDescriptionParagraphs() []string {
|
|
return SplitParagraph(c.Description)
|
|
}
|
|
|
|
func (c Bundle) DisplayTitle() string {
|
|
return DisplayTitle(c.Name)
|
|
}
|
|
|
|
// New creates a new Bundle wired to the given datastore.
|
|
func New(db *datastore.Datastore) *Bundle {
|
|
b := new(Bundle)
|
|
b.Init(db)
|
|
return b
|
|
}
|
|
|
|
// Query returns a datastore query for bundles.
|
|
func Query(db *datastore.Datastore) datastore.Query {
|
|
return db.Query("bundle")
|
|
}
|