discount

package
v1.45.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 15 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

View Source
const (
	Flat         Type = "flat"
	Percent           = "percent"
	FreeShipping      = "free-shipping"
	FreeItem          = "free-item"
	Bulk              = "bulk"
)

Variables

Functions

func GetScopedDiscounts

func GetScopedDiscounts(ctx context.Context, sc scope.Type, id string, keyc chan []iface.Key, errc chan error)

func Query

Types

type Discount

type Discount struct {
	mixin.Model[Discount]

	Name string `json:"name"`

	// Type of discount rule
	Type Type `json:"type"`

	// Date range in which discount is valid
	StartDate time.Time `json:"startDate"`
	EndDate   time.Time `json:"endDate"`

	Scope Scope `json:"scope"`

	Target Target `json:"target"`

	// Rules for this discount
	Rules []Rule `json:"rules" orm:"default:[]"`

	// Whether discount is enabled.
	Enabled bool `json:"enabled" orm:"default:true"`
}

func Fake

func Fake(db *datastore.Datastore) *Discount

func New

func New(db *datastore.Datastore) *Discount

func (*Discount) AfterCreate

func (d *Discount) AfterCreate() error

Invalidate cache based on scope

func (*Discount) AfterDelete

func (d *Discount) AfterDelete() error

func (*Discount) AfterUpdate

func (d *Discount) AfterUpdate(previous *Discount) error

func (Discount) ScopeId

func (d Discount) ScopeId() string

func (Discount) ValidFor

func (d Discount) ValidFor(t time.Time) bool

type Rule

type Rule struct {
	// Condition which triggers this rule
	Trigger rule.Trigger `json:"trigger"`

	// Action which happens as result of trigger
	Action rule.Action `json:"action"`
}

Encompasses a given rule trigger and discount amount

type Scope

type Scope struct {
	// The scope these rules qualify against
	Type scope.Type `json:"type"`

	// Id for this rule
	StoreId      string `json:"storeId,omitempty"`
	CollectionId string `json:"collectionId,omitempty"`
	ProductId    string `json:"productId,omitempty"`
	VariantId    string `json:"variantId,omitempty"`
}

type Target

type Target struct {
	// Target for which all rules apply
	Type target.Type `json:"type"`

	// Id for the target
	ProductId string `json:"productId,omitempty"`
	VariantId string `json:"variantId,omitempty"`
}

type Type

type Type string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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