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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Accept class name or shorthand in CalculatedAdjustments#calculator_type=
Damian Legawiecd30bc62c2d70
diff --git a/spree/core/app/models/concerns/spree/calculated_adjustments.rb b/spree/core/app/models/concerns/spree/calculated_adjustments.rbindex bfde8972cb..4d28f79a9e 100644--- a/spree/core/app/models/concerns/spree/calculated_adjustments.rb+++ b/spree/core/app/models/concerns/spree/calculated_adjustments.rb@@ -18,15 +18,22 @@ module Spreecalculator.class.to_s if calculatorend- # Look up a calculator by its wire shorthand (`'flat_rate'`) against- # the calculators registered for this parent. Scoping to the- # registered set ensures a `CreateAdjustment` action can't be- # assigned a shipping-only calculator just by knowing its shorthand.+ # Accepts a fully-qualified class name (`'Spree::Calculator::FlatRate'`)+ # or the public API shorthand (`'flat_rate'`). Shorthand is resolved+ # against this parent's registered calculators so a CreateAdjustment+ # can't be assigned a shipping-only calculator just by knowing its+ # name.def calculator_type=(calculator_type)return if calculator_type.blank?- registry = self.class.respond_to?(:calculators) ? self.class.calculators : []- klass = registry.find { |k| k.api_type == calculator_type.to_s }+ str = calculator_type.to_s+ klass =+ if str.include?('::')+ str.safe_constantize+ else+ registry = self.class.respond_to?(:calculators) ? self.class.calculators : []+ registry.find { |k| k.api_type == str }+ endself.calculator = klass.new if klass && !calculator.instance_of?(klass)end