Class: Spree::OrderRouting::Strategy::Rules

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

Overview

Default order routing strategy: walks Spree::OrderRoutingRule rows in priority order, runs the Reducer to fully rank eligible locations, packs each location, and lets Spree::Stock::Prioritizer distribute inventory units across packages so units that the top-ranked location can't cover spill over to subsequent locations.

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

Instance Attribute Summary

Attributes inherited from Base

#order

Instance Method Summary collapse

Methods inherited from Base

display_name, #initialize

Methods included from ApiTyped

#api_type, api_type_for, #api_typed_family, class_name_for, find, registered_class

Constructor Details

This class inherits a constructor from Spree::OrderRouting::Strategy::Base

Instance Method Details

#for_allocation ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/spree/order_routing/strategy/rules.rb', line 12

def for_allocation
  locations = coordinator.candidate_stock_locations
  return [] if locations.empty?

  ordered = Spree::OrderRouting::Strategy::Reducer
    .new(applicable_rules.to_a, order: order)
    .rank_all(locations)
  return [] if ordered.empty?

  # Packed in rank order through the Coordinator, so an order allocates
  # under the same delivery profile and channel coverage as its cart,
  # and the Prioritizer's first-package-wins-on-hand logic honors the
  # routing decision between origins that can reach the destination.
  coordinator.estimate_packages(coordinator.allocated_packages(ordered))
end

#for_cancellation ⇒ Object



36
# File 'app/models/spree/order_routing/strategy/rules.rb', line 36

def for_cancellation; end

#for_release ⇒ Object



35
# File 'app/models/spree/order_routing/strategy/rules.rb', line 35

def for_release; end

#for_sale(fulfillment:) ⇒ Object

Stock decrement / restock today happens via Spree::Fulfillment's state machine (after_ship / after_cancel). The strategy methods below are part of the contract for the future reservation + typed-movement phase — see 6.0-stock-reservations.md and 6.0-typed-stock-movements.md. In 5.5 they are no-ops; the existing model callbacks already do the right thing.



34
# File 'app/models/spree/order_routing/strategy/rules.rb', line 34

def for_sale(fulfillment:); end