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

Inherits:
Object
  • Object
show all
Extended by:
ApiTyped
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

Rules

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiTyped

api_type, api_type_for, api_typed_family, class_name_for, find, registered_class

Constructor Details

#initialize(order:) ⇒ Base

Returns a new instance of Base.



25
26
27
# File 'app/models/spree/order_routing/strategy/base.rb', line 25

def initialize(order:)
  @order = order
end

Instance Attribute Details

#order ⇒ Object (readonly)

Returns the value of attribute order.



15
16
17
# File 'app/models/spree/order_routing/strategy/base.rb', line 15

def order
  @order
end

Class Method Details

.display_name ⇒ String

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

Returns:

  • (String)


21
22
23
# File 'app/models/spree/order_routing/strategy/base.rb', line 21

def self.display_name
  I18n.t("spree.order_routing.strategies.#{name.demodulize.underscore}", default: name.demodulize.titleize)
end

Instance Method Details

#for_allocation ⇒ Array<Spree::Stock::Package>

Returns:

Raises:

  • (NotImplementedError)


30
31
32
# File 'app/models/spree/order_routing/strategy/base.rb', line 30

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

#for_cancellation ⇒ Object

Raises:

  • (NotImplementedError)


43
44
45
# File 'app/models/spree/order_routing/strategy/base.rb', line 43

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

#for_release ⇒ Object

Raises:

  • (NotImplementedError)


39
40
41
# File 'app/models/spree/order_routing/strategy/base.rb', line 39

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

#for_sale(fulfillment:) ⇒ Object

Parameters:

Raises:

  • (NotImplementedError)


35
36
37
# File 'app/models/spree/order_routing/strategy/base.rb', line 35

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