Class: Spree::OrderRoutingRule

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Includes:
SingleStoreResource
Defined in:
app/models/spree/order_routing_rule.rb

Overview

STI base for order routing rules. Subclasses live in app/models/spree/order_routing/rules/ and implement #rank(order, locations).

Plugins extend the engine by defining a new subclass:

class AcmeFresh::OrderRouting::RefrigeratedRule < Spree::OrderRoutingRule
preference :max_temp_c, :integer, default: 4

def rank(order, locations)
  # ... return Array<LocationRanking>
end
end

See docs/plans/6.0-order-routing.md.

Defined Under Namespace

Modules: ClassMethods Classes: LocationRanking

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descriptionObject

Feeds the description field of subclasses_with_preference_schema (the /types discovery payload), which only reads .description.



66
67
68
# File 'app/models/spree/order_routing_rule.rb', line 66

def self.description
  human_description
end

.human_descriptionString

Returns localized description for the rule kind.

Returns:

  • (String)

    localized description for the rule kind



60
61
62
# File 'app/models/spree/order_routing_rule.rb', line 60

def self.human_description
  Spree.t("order_routing_rule_types.#{api_type}.description", default: '')
end

.human_nameString

Returns localized display name for the rule kind, used by admin pickers.

Returns:

  • (String)

    localized display name for the rule kind, used by admin pickers



55
56
57
# File 'app/models/spree/order_routing_rule.rb', line 55

def self.human_name
  Spree.t("order_routing_rule_types.#{api_type}.name", default: api_type.titleize)
end

Instance Method Details

#human_descriptionObject



71
# File 'app/models/spree/order_routing_rule.rb', line 71

def human_description = self.class.human_description

#human_nameObject



70
# File 'app/models/spree/order_routing_rule.rb', line 70

def human_name = self.class.human_name

#rank(_order, _locations) ⇒ Array<LocationRanking>

Subclasses override. Returns an Array — one per location, with rank=nil to abstain.

Parameters:

Returns:

Raises:

  • (NotImplementedError)


79
80
81
# File 'app/models/spree/order_routing_rule.rb', line 79

def rank(_order, _locations)
  raise NotImplementedError, "#{self.class} must implement #rank(order, locations)"
end