draftorder

package
v1.49.39 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package draftorder is the admin order-builder domain (Medusa v2 parity: admin/draft-orders). A draft order is an order an admin composes on a customer's behalf — a currency, a customer reference, and a set of line items — that is later converted into a REAL order (models/order) with the same items and total.

Line items are separate facts (models/draftorderitem), one row per line, so the builder can add/remove them independently. The draft's total is a PROJECTION over those lines (Σ unitPrice × qty), never a mutable counter — the same values-not-places design the gift-card ledger uses.

Index

Constants

View Source
const (
	StatusDraft    = "draft"
	StatusComplete = "complete"
)

Draft order lifecycle states.

Variables

This section is empty.

Functions

func Items

func Items(db *datastore.Datastore, draftOrderId string) ([]*draftorderitem.DraftOrderItem, error)

Items returns the line items of a draft order, scoped to db's namespace. The lines are facts; the draft's total is projected from them (TotalCents).

func Query

func TotalCents

func TotalCents(items []*draftorderitem.DraftOrderItem) currency.Cents

TotalCents projects the draft order total from its line items: Σ(unitPrice × quantity). It is derived, never stored, so add/remove of a line can never leave a stale total behind.

Types

type DraftOrder

type DraftOrder struct {
	mixin.Model[DraftOrder]

	// Customer this draft is being built for (optional until complete).
	CustomerId string `json:"customerId,omitempty"`
	Email      string `json:"email,omitempty"`

	Currency currency.Type `json:"currency" orm:"default:usd"`

	Status string `json:"status" orm:"default:draft"`

	// OrderId is the real order this draft was converted into (set on complete).
	OrderId string `json:"orderId,omitempty"`

	Metadata  Map    `json:"metadata,omitempty" datastore:"-"`
	Metadata_ string `json:"-" datastore:",noindex"`
}

DraftOrder is an in-progress order an admin builds for a customer. It holds no line items itself; those are draftorderitem rows keyed by DraftOrderId. Once completed, OrderId points at the real order it produced and Status is StatusComplete (terminal).

func New

func New(db *datastore.Datastore) *DraftOrder

func (*DraftOrder) IsDraft

func (d *DraftOrder) IsDraft() bool

IsDraft reports whether the draft can still be edited and completed. An empty status is treated as draft (the orm default) so a freshly-created row is editable before its first save round-trips the default.

func (*DraftOrder) Load

func (d *DraftOrder) Load(ps []datastore.Property) (err error)

func (*DraftOrder) Save

func (d *DraftOrder) Save() ([]datastore.Property, error)

Jump to

Keyboard shortcuts

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