Class: Spree::Discount

Inherits:
Object
  • Object
show all
Includes:
TypedAdjustmentLine
Defined in:
app/models/spree/discount.rb

Overview

A promotion or manual discount on a line item or fulfillment. Amount is enforced non-positive (validation + DB CHECK). Provenance snapshots (+code+, value, value_type) keep rows meaningful after the promotion is deleted — the promotion FKs are nullified, never cascaded.

Order-level discounts are distributed proportionally across line items at application time (largest-remainder) — there are no order-attached rows.

Constant Summary collapse

KINDS =

promotion rows are written by promotion actions, manual ones by an admin on a placed order.

%w[promotion manual].freeze

Instance Method Summary collapse

Methods included from TypedAdjustmentLine

#currency, #order=, #owner

Instance Method Details

#adjustable ⇒ Spree::LineItem, ...



37
38
39
# File 'app/models/spree/discount.rb', line 37

def adjustable
  line_item || fulfillment
end

#promotion? ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/spree/discount.rb', line 41

def promotion?
  kind == 'promotion'
end