currency

package
v1.49.44 Latest Latest
Warning

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

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

Documentation

Overview

Package currency is the currency entity domain: the reference table of the currencies a store accepts, addressable by ISO-4217 Code. It is a global (default-namespace) reference set — the single source the store/settings and product/price currency pickers read, replacing a hardcoded array. The bare value type (usd/eur/…) and its symbol/decimal conventions still live in models/types/currency; this entity carries the editable, seedable rows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Query

func Seed

func Seed(db *datastore.Datastore) (created int, err error)

Seed inserts the common currencies into db (which must be the default-namespace reference store). IDEMPOTENT + NON-DESTRUCTIVE: a currency whose code already exists is left untouched (admin edits are never clobbered); only missing codes are created. Returns the number created.

func SeedIfEmpty

func SeedIfEmpty(db *datastore.Datastore) (created int, err error)

SeedIfEmpty seeds the reference currencies only when the table is empty — a cheap count query gates the per-row create, so it is safe to call on every bootstrap (mirrors catalogentry.SeedIfEmpty). Once any currency exists (seeded or admin-created) it never re-runs, so admin edits stay authoritative.

Types

type Currency

type Currency struct {
	mixin.Model[Currency]

	// Code is the lowercase ISO-4217 code (e.g. "usd"). Unique reference key.
	Code string `json:"code"`

	// Symbol is the display glyph (e.g. "$", "€", "¥").
	Symbol string `json:"symbol"`

	// Name is the human-facing currency name (e.g. "US Dollar").
	Name string `json:"name"`

	// DecimalDigits is the number of minor-unit decimal places (2 for usd, 0 for jpy).
	DecimalDigits int `json:"decimalDigits"`

	// IncludesTax marks prices in this currency as tax-inclusive.
	IncludesTax bool `json:"includesTax"`
}

Currency is one accepted currency, keyed by its lowercase ISO-4217 Code (unique). DecimalDigits is the minor-unit exponent (2 for usd, 0 for jpy); IncludesTax marks currencies whose displayed prices are tax-inclusive.

func New

func New(db *datastore.Datastore) *Currency

func (*Currency) Normalize

func (c *Currency) Normalize()

Normalize lowercases the code before save so lookups are case-insensitive and the uniqueness key is canonical.

Jump to

Keyboard shortcuts

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