store

package
v1.49.33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSlug = "default"

DefaultSlug is the stable slug of the store every org gets on first use. It is safe to reuse across tenants because each org's merchant rows live in its OWN namespaced store (datastore.NewNamespaced), so the slug never collides.

Variables

View Source
var ListingFields = reflect.FieldNames(Listing{})

Functions

func Query

Types

type Listing

type Listing struct {
	// Not customizable
	ProductId string        `json:"productId,omitempty"`
	Slug      string        `json:"slug,omitempty"`
	VariantId string        `json:"variantId,omitempty"`
	SKU       string        `json:"sku,omitempty"`
	Currency  currency.Type `json:"currency,omitempty"`

	Name *string `json:"name"`

	Headline    *string `json:"headline,omitempty"`
	Excerpt     *string `json:"excerpt,omitempty"`
	Description *string `json:"description,omitempty"`

	// Product Media
	HeaderImage *Media   `json:"headerImage,omitempty"`
	Media       *[]Media `json:"media,omitempty"`

	Sold *int `json:"sold"`

	Price     *currency.Cents `json:"price,omitempty"`
	ListPrice *currency.Cents `json:"listPrice,omitempty"`
	Shipping  *currency.Cents `json:"shipping,omitempty"`
	Taxable   *bool           `json:"taxable,omitempty"`

	WeightUnit *weight.Unit `json:"weightUnit,omitempty"`

	Available    *bool         `json:"available,omitempty"`
	Availability *Availability `json:"availability,omitempty"`

	Hidden *bool `json:"hidden,omitempty"`
}

Everything is a pointer, which allows fields to be nil. This way when we serialize to/from JSON we know what has and has not been set.

type Listings

type Listings map[string]Listing

type ShippingRateTable

type ShippingRateTable map[string]shipping.Rates

type Store

type Store struct {
	mixin.Model[Store]

	// Full name of store
	Name string `json:"name"`

	// Unique human readable id for url <slug>.hanzo.aie
	Slug string `json:"slug"`

	// Where this is hosted if not on hanzo.ai
	Domain string `json:"domain"`
	Prefix string `json:"prefix"`

	// Currency for store
	Currency currency.Type `json:"currency"`

	Address  Address   `json:"address,omitempty"`
	TaxNexus []Address `json:"taxNexus,omitempty"`

	// Overrides per item
	Listings  Listings `json:"listings" datastore:"-" orm:"default:{}"`
	Listings_ string   `json:"-" datastore:",noindex"`

	Salesforce struct {
		PriceBookId string `json:"PriceBookId"`
	} `json:"-"`

	Email           string `json:"email,omitempty"`
	Phone           string `json:"phone,omitempty"`
	Timezone        string `json:"timezone,omitempty"`
	ReferralBaseUrl string `json:"referralBaseUrl,omitempty"`

	Mailchimp struct {
		ListId string `json:"listId"`
		APIKey string `json:"apiKey"`
	} `json:"mailchimp,omitempty"`
}

func EnsureDefault added in v1.47.2

func EnsureDefault(db *datastore.Datastore) (*Store, error)

EnsureDefault returns the org's default store, creating it on first use. This is the ONE canonical way an org gets its commerce store: idempotent (keyed by the stable DefaultSlug), org-scoped (db MUST be a per-org datastore.NewNamespaced), and carrying NO payment credentials — binding Square/Stripe stays a separate business step. It replaces the long-dead commented-out provisioning in util/provision: a store is lazily provisioned at the first authenticated GET /v1/store/current instead of eagerly at org creation.

func Fake

func Fake(db *datastore.Datastore) *Store

func New

func New(db *datastore.Datastore) *Store

func (*Store) AddListing

func (s *Store) AddListing(id string, listing Listing)

Add a new listing to the listings map

func (*Store) AfterCreate

func (s *Store) AfterCreate() error

Hooks

func (*Store) Defaults

func (s *Store) Defaults()

Defaults sets runtime defaults that cannot be expressed as orm tags.

func (Store) GetShippingRates

func (s Store) GetShippingRates() (*shippingrates.ShippingRates, error)

Return ShippingRates

func (Store) GetTaxRates

func (s Store) GetTaxRates() (*taxrates.TaxRates, error)

Return TaxRates

func (*Store) Load

func (s *Store) Load(ps []datastore.Property) (err error)

func (*Store) Save

func (s *Store) Save() (ps []datastore.Property, err error)

func (*Store) UpdateFromListing

func (s *Store) UpdateFromListing(entity mixin.Entity)

Update product/variant using listing for said item

func (*Store) Validator

func (s *Store) Validator() *val.Validator

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL