shipping

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: 5 Imported by: 1 module, 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formula

type Formula struct {
	MinWeight weight.Mass    `json:"minWeight"`
	RateType  RateType       `json:"type"`
	Price     currency.Cents `json:"price"`
}

This represents the minimum value of a shipping formula

for example: Shipping = $10 Flat Rate if weight > 10 lbs

type RateType

type RateType string
const (
	Flat     RateType = "flat"
	Variable          = "variable"
)

type Rates

type Rates struct {
	Formulas   []Formula     `json:"formulas"`
	WeightUnit weight.Unit   `json:"weightUnit"`
	Currency   currency.Type `json:"currency"`

	// Rate used by default
	BaseRateType RateType       `json:"type"`
	BasePrice    currency.Cents `json:"price"`
}

A collection of shipping rate formulas, all must have a common weight and currency unit

func (Rates) GetPrice

func (r Rates) GetPrice(p *product.Product) (currency.Cents, currency.Type)

To calculate shipping rate, we sort an array of formulas by the MinWeight ascending When we find the first element with a weight greater than a min, we calculate using the previous one

func (Rates) Len

func (r Rates) Len() int

func (Rates) Less

func (r Rates) Less(i, j int) bool

func (*Rates) Swap

func (r *Rates) Swap(i, j int)

Jump to

Keyboard shortcuts

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