cart

package module
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 6 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cart

The commerce cart module: guest-first, server-side carts with live catalog pricing. Carts are keyed by opaque bearer tokens; only the token hash is stored. Prices are never persisted — totals resolve live from the catalog at read time, so price edits apply immediately.

Owns

  • cart_carts / cart_items tables (module migration, schema_migrations_cart); variant 0 means the base-product line so the line uniqueness constraint behaves identically on every driver.
  • POST /api/v1/public/cart — mints a token (response body and X-Cart-Token header) with an empty cart.
  • GET /api/v1/public/cart — the live-priced cart: lines, subtotal, item count, currency.
  • DELETE /api/v1/public/cart — empties and removes the cart.
  • POST /api/v1/public/cart/items — resolves the sellable line and merges it (same product and variant add up, capped at 99 per line); out-of-stock demand is refused.
  • PATCH /api/v1/public/cart/items/{itemId} — replaces a line quantity.
  • DELETE /api/v1/public/cart/items/{itemId} — drops one line.

Tokens ride the X-Cart-Token header, falling back to a body token field on bodyless requests. Unknown or missing tokens read as unauthorized; unknown products and variants as not found.

Seams

  • CatalogSource — sellable-line resolution (composition root adapts the catalog service; unknown lookups wrap the cart sentinels).
  • CartStore — persistence (the single-source store satisfies it).
  • Display currency (adopted from the catalog configuration).

Not here (yet)

The checkout handoff lands with the orders module; tax, shipping, and vouchers stay out of totals until the pricing phase. No admin surface, no config block, no capabilities — the surface is fully anonymous.

Documentation

Overview

Package cart is the official commerce cart module: guest-first, server-side carts with live catalog pricing. Carts are keyed by opaque bearer tokens and served on the public router; the module carries no admin surface and no config of its own.

Index

Constants

View Source
const (
	// Name is the registry key for this module.
	Name = "cart"

	// Version is the module version reported via Module.Version.
	Version = "0.1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module is the cart kernel module.

func New

func New(options ...Option) *Module

New builds the module and constructs the handler once, so every endpoint shares the adopted service.

func (*Module) Init

func (m *Module) Init(_ kernel.Kernel) error

Init wires the module. The handler is already built by New; Init only validates presence. Migration execution is core-driven (it needs the live *sql.DB, which modules never touch directly).

func (*Module) Migrations

func (m *Module) Migrations() fs.FS

Migrations returns the embedded migration filesystem, laid out per driver subdirectory (the core migration runner selects via Driver.MigrationDir).

func (*Module) Name

func (m *Module) Name() string

Name returns the registry key.

func (*Module) Optional

func (m *Module) Optional() []string

Optional lists soft dependencies. None.

func (*Module) RegisterPublicRoutes

func (m *Module) RegisterPublicRoutes(router chi.Router)

RegisterPublicRoutes mounts the cart surface on the public router (rate-limited, no auth chain): token minting, cart reads, line management, and cart deletion.

func (*Module) Requires

func (m *Module) Requires() []string

Requires lists hard dependencies. Carts price from the catalog: the module resolves sellable lines through the catalog service it adopts, so disabling catalog cascades the cart off the registry.

func (*Module) Shutdown

func (m *Module) Shutdown() error

Shutdown releases nothing: the handler holds no runtime resources.

func (*Module) Version

func (m *Module) Version() string

Version returns the module version.

type Option

type Option func(*Module)

Option configures a Module. The composition root supplies every option; direct construction without options yields a standalone module that serves nothing (handlers built over nil dependencies must not be invoked).

func WithCurrency

func WithCurrency(currency string) Option

WithCurrency sets the display currency for cart payloads, adopted from the catalog configuration. Empty renders payloads without a currency.

func WithLogger

func WithLogger(logger kernel.Logger) Option

WithLogger attaches the module logger. Without one handler failures are dropped (discard sink).

func WithService

func WithService(service *cartdomain.Service) Option

WithService adopts the cart domain service (composition root). The same instance backs every endpoint so token resolution and totals run identically across the surface.

Directories

Path Synopsis
Package api hosts the cart module's public HTTP surface: token minting, cart reads, line management, and cart deletion.
Package api hosts the cart module's public HTTP surface: token minting, cart reads, line management, and cart deletion.
Package cart is the official commerce cart module: guest-first, server-side carts with live catalog pricing.
Package cart is the official commerce cart module: guest-first, server-side carts with live catalog pricing.
Package store is the single-source cart repository: one implementation against *sql.DB plus a kernel Dialect, following the comments/media store pattern.
Package store is the single-source cart repository: one implementation against *sql.DB plus a kernel Dialect, following the comments/media store pattern.
Package testutil provides the kernel fixture module tests run against.
Package testutil provides the kernel fixture module tests run against.

Jump to

Keyboard shortcuts

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