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

31 lines
1007 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package draftorder
import (
"github.com/hanzoai/commerce/datastore"
"github.com/hanzoai/commerce/models/draftorderitem"
"github.com/hanzoai/commerce/models/types/currency"
)
// 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 Items(db *datastore.Datastore, draftOrderId string) ([]*draftorderitem.DraftOrderItem, error) {
items := make([]*draftorderitem.DraftOrderItem, 0, 16)
if _, err := draftorderitem.Query(db).
Filter("DraftOrderId=", draftOrderId).
GetAll(&items); err != nil {
return nil, err
}
return items, nil
}
// 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.
func TotalCents(items []*draftorderitem.DraftOrderItem) currency.Cents {
var total currency.Cents
for _, i := range items {
total += i.TotalCents()
}
return total
}