boomerdigital / solidus_avatax_certified

Improve your Solidus store's sales tax decision automation with Avalara AvaTax

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined local variable or method `default_environment' for Spree::AvataxConfiguration:Class (NameError)

tmtrademarked opened this issue · comments

When working through the setup instructions, after installing the gem and running the migrations, I'm getting the following error when attempting to start my application:

undefined local variable or method `default_environment' for Spree::AvataxConfiguration:Class (NameError)

I've created an initializer that looks like the following:

# frozen_string_literal: true

Spree::Avatax::Config.configure do |config|
  config.company_code = ENV['AVATAX_COMPANY_CODE']
  config.license_key = ENV['AVATAX_LICENSE_KEY']
  config.account = ENV['AVATAX_ACCOUNT']
  config.environment = ENV['AVATAX_ENVIRONMENT'].presence || (Rails.env.production? ? :production : :sandbox)
  config.log = true
  config.log_to_stdout = true
  config.address_validation = true
  config.address_validation_enabled_countries = ['United States']
  config.tax_calculation = true
  config.document_commit = true
  config.origin = '{}'
  config.refuse_checkout_address_validation_error = false
  config.customer_can_validate = false
  config.raise_exceptions = false 
end

But from what I can tell, the problem seems to be that Spree::AvataxConfiguration is attempting to call default_environment as a class method, when it is defined as an instance method. Am I misunderstanding something here?

I'm using Solidus 3.1.4, Ruby 3.0, and Rails 6.1.4.4.

I suspect this may have been a change in behavior in Solidus 3.1, based on the warning messages I'm seeing. I guess the question is whether this gem is intending to support 3.1+, and if so, how we'd have to change this proc.

DEPRECATION WARNING: The arity of a proc given as the default for a preference
has changed from 0 to 1 on Solidus 3.1. The Solidus
version for the loaded preference defaults is given as the
proc's argument from this point on.

If you don't need to return a different default value
depending on the loaded Solidus version, you can change
the proc so that it doesn't have lambda semantics (lambdas
raise when extra arguments are supplied, while raw procs
don't). E.g.:

preference :foo, :string, default: proc { true }

If you want to branch on the provided Solidus version, you can do like the following:

preference :foo, :string, default: by_version(true, "3.2.0" => false)