discount

package
v1.39.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 15 Imported by: 0

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