Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tmtrademarked opened this issue Dec 16, 2021 · 1 comment

Comments

@tmtrademarked
Copy link
Contributor

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.

@tmtrademarked
Copy link
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant