promotions
Build and Publish / BuildAndDeployArm64 (push) Failing after 6s
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled

This commit is contained in:
2026-06-18 11:32:19 +02:00
parent 2545be4315
commit 2443fd8b49
9 changed files with 583 additions and 55 deletions
+21 -2
View File
@@ -100,14 +100,33 @@ func NewContextFromCart(g *cart.CartGrain, opts ...ContextOption) *PromotionEval
// PromotionService evaluates PromotionRules against a PromotionEvalContext.
type PromotionService struct {
tracer Tracer
// effects is the per-action-type behaviour registry. Each Effect both applies
// its action to the cart (when the owning rule qualifies) and reports its own
// progress, so any effect type can surface "spend X more for ..." nudges —
// even one that has already applied (e.g. a tiered discount at 5% pointing at
// the next 9% tier). Register a new Effect to add a new action type.
effects map[ActionType]Effect
}
// NewPromotionService constructs a PromotionService with an optional tracer.
// NewPromotionService constructs a PromotionService with an optional tracer and
// the built-in effect handlers.
func NewPromotionService(t Tracer) *PromotionService {
if t == nil {
t = NoopTracer{}
}
return &PromotionService{tracer: t}
return &PromotionService{
tracer: t,
effects: defaultEffects(),
}
}
// RegisterEffect adds (or overrides) the handler for an action type, so new
// applied/pending effects can be plugged in without touching the engine.
func (s *PromotionService) RegisterEffect(e Effect) {
if s.effects == nil {
s.effects = map[ActionType]Effect{}
}
s.effects[e.Type()] = e
}
// EvaluationResult holds the outcome of evaluating a single rule.