validation

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: OSL-3.0 Imports: 7 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddToCartNotAllowed

type AddToCartNotAllowed struct {
	Reason              string
	RedirectHandlerName string
	RedirectParams      map[string]string
}

AddToCartNotAllowed error

func (*AddToCartNotAllowed) Error

func (e *AddToCartNotAllowed) Error() string

Error message

func (*AddToCartNotAllowed) MessageCode

func (e *AddToCartNotAllowed) MessageCode() string

MessageCode message code

type ItemValidationError

type ItemValidationError struct {
	ItemID          string
	ErrorMessageKey string
}

ItemValidationError applies for a single item

type ItemValidator

type ItemValidator interface {
	Validate(ctx context.Context, session *web.Session, deliveryCode string, request cart.AddRequest, product domain.BasicProduct) error
}

ItemValidator checks a cart item

type MaxQuantityRestrictor

type MaxQuantityRestrictor interface {
	// Name returns the code of the restrictor
	Name() string
	// Restrict must return a `RestrictionResult` which contains information regarding if a restriction is
	// applied and whats the max allowed quantity
	Restrict(ctx context.Context, product domain.BasicProduct, cart *cart.Cart, deliveryCode string) *RestrictionResult
}

MaxQuantityRestrictor returns the maximum qty allowed for a given product and cart it is possible to register many (MultiBind) MaxQuantityRestrictor implementations

type RestrictionResult

type RestrictionResult struct {
	IsRestricted        bool
	MaxAllowed          int
	RemainingDifference int
	RestrictorName      string
}

RestrictionResult contains the result of a restriction

type RestrictionService

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

RestrictionService checks product restriction

func (*RestrictionService) Inject

func (rs *RestrictionService) Inject(
	qtyRestrictors []MaxQuantityRestrictor,
) *RestrictionService

Inject dependencies

func (*RestrictionService) RestrictQty

func (rs *RestrictionService) RestrictQty(ctx context.Context, product domain.BasicProduct, currentCart *cart.Cart, deliveryCode string) *RestrictionResult

RestrictQty checks if there is an qty restriction present and returns an according result containing the max allowed quantity and the quantity difference to the current cart

type Result

type Result struct {
	HasCommonError        bool
	CommonErrorMessageKey string
	ItemResults           []ItemValidationError
}

Result groups the validation result

func (Result) GetErrorMessageKeyForItem

func (c Result) GetErrorMessageKeyForItem(id string) string

GetErrorMessageKeyForItem returns the specific error message for that item

func (Result) HasErrorForItem

func (c Result) HasErrorForItem(id string) bool

HasErrorForItem checks if a specified item has an error

func (Result) IsValid

func (c Result) IsValid() bool

IsValid is valid is true if no errors occurred

type Validator

type Validator interface {
	Validate(ctx context.Context, session *web.Session, cart *decorator.DecoratedCart) Result
}

Validator checks a complete decorated cart

Jump to

Keyboard shortcuts

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