shipping

package
v1.36.4 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 5 Imported by: 0

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