Class: Spree::StateChangeTracker

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/state_change_tracker.rb

Overview

Configurable class to enqueue state change tracking jobs Configure your custom logic by setting Spree::Config.state_change_tracking_class

Examples:

Spree::Config.state_change_tracking_class = MyCustomTracker

Class Method Summary collapse

Class Method Details

.call(stateful:, previous_state:, current_state:, transition_timestamp:, stateful_name: stateful.class.model_name.element) ⇒ Object

Parameters:

  • stateful (Object)

    The stateful object to track changes for

  • previous_state (String)

    The previous state of the order

  • current_state (String)

    The current state of the order

  • transition_timestamp (Time)

    When the state transition occurred

  • stateful_name (String) (defaults to: stateful.class.model_name.element)

    The element name of the state transition being tracked. It defaults to the stateful model element name.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/spree/state_change_tracker.rb', line 14

def self.call(
  stateful:,
  previous_state:,
  current_state:,
  transition_timestamp:,
  stateful_name: stateful.class.model_name.element
)
  # Enqueue a background job to track this state change
  StateChangeTrackingJob.perform_later(
    stateful,
    previous_state,
    current_state,
    transition_timestamp,
    stateful_name
  )
end