Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix order routing reducer constant lookup (#14168)

Chiu7a254a1a5c6c
diff --git a/spree/core/app/models/spree/order_routing/strategy/rules.rb b/spree/core/app/models/spree/order_routing/strategy/rules.rb
index f9c40db2b7..0f94705984 100644
--- a/spree/core/app/models/spree/order_routing/strategy/rules.rb
+++ b/spree/core/app/models/spree/order_routing/strategy/rules.rb
@@ -13,7 +13,9 @@ module Spree
locations = eligible_locations
return [] if locations.empty?
- ordered = Reducer.new(applicable_rules.to_a, order: order).rank_all(locations)
+ ordered = Spree::OrderRouting::Strategy::Reducer
+ .new(applicable_rules.to_a, order: order)
+ .rank_all(locations)
return [] if ordered.empty?
packages = build_packages(ordered)
diff --git a/spree/core/spec/models/spree/order_routing/strategy/rules_spec.rb b/spree/core/spec/models/spree/order_routing/strategy/rules_spec.rb
index f8be7204de..effd00295a 100644
--- a/spree/core/spec/models/spree/order_routing/strategy/rules_spec.rb
+++ b/spree/core/spec/models/spree/order_routing/strategy/rules_spec.rb
@@ -35,5 +35,21 @@ RSpec.describe Spree::OrderRouting::Strategy::Rules, type: :model do
packages = subject.for_allocation
expect(packages.map(&:stock_location)).to all(eq(preferred_loc))
end
+
+ it 'resolves the reducer from the strategy namespace' do
+ stub_const(
+ "#{described_class}::Reducer",
+ Class.new do
+ def initialize(*); end
+
+ def rank_all(*)
+ raise 'nested reducer should not be used'
+ end
+ end
+ )
+
+ packages = subject.for_allocation
+ expect(packages.map(&:stock_location)).to all(eq(default_loc))
+ end
end
end