Class: Spree::OrderRouting::Strategy::Base

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/order_routing/strategy/base.rb

Overview

Contract for order routing strategies. Subclasses implement all four methods — there are no defaults. New routing signals (proximity, day-of-week, etc.) ship as STI subclasses of Spree::OrderRoutingRule; a custom strategy is appropriate only when the algorithm itself is a different shape (OMS delegation, ML model, optimization solver).

Selected per Order via Spree::Order#order_routing_strategy. See docs/plans/6.0-order-routing.md.

Direct Known Subclasses

Legacy, Rules

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order:) ⇒ Base

Returns a new instance of Base.



23
24
25
# File 'app/models/spree/order_routing/strategy/base.rb', line 23

def initialize(order:)
  @order = order
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



13
14
15
# File 'app/models/spree/order_routing/strategy/base.rb', line 13

def order
  @order
end

Class Method Details

.display_nameString

Human label for admin strategy pickers. Override in a subclass or add an i18n key under spree.order_routing.strategies.

Returns:

  • (String)


19
20
21
# File 'app/models/spree/order_routing/strategy/base.rb', line 19

def self.display_name
  Spree.t(name.demodulize.underscore, scope: 'order_routing.strategies', default: name.demodulize.titleize)
end

Instance Method Details

#for_allocationArray<Spree::Stock::Package>

Returns:

Raises:

  • (NotImplementedError)


28
29
30
# File 'app/models/spree/order_routing/strategy/base.rb', line 28

def for_allocation
  raise NotImplementedError, "#{self.class} must implement #for_allocation"
end

#for_cancellationObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'app/models/spree/order_routing/strategy/base.rb', line 41

def for_cancellation
  raise NotImplementedError, "#{self.class} must implement #for_cancellation"
end

#for_releaseObject

Raises:

  • (NotImplementedError)


37
38
39
# File 'app/models/spree/order_routing/strategy/base.rb', line 37

def for_release
  raise NotImplementedError, "#{self.class} must implement #for_release"
end

#for_sale(fulfillment:) ⇒ Object

Parameters:

Raises:

  • (NotImplementedError)


33
34
35
# File 'app/models/spree/order_routing/strategy/base.rb', line 33

def for_sale(fulfillment:)
  raise NotImplementedError, "#{self.class} must implement #for_sale"
end