spree-contrib / spree_multi_vendor

Spree marketplace extension. Create your own marketplace on top of Spree Commerce
https://spreecommerce.org/marketplace-ecommerce/
BSD 3-Clause "New" or "Revised" License
142 stars 135 forks source link

NameError (uninitialized constant SpreeMultiVendor::Spree::Preferences) #174

Closed hoshinotsuyoshi closed 3 years ago

hoshinotsuyoshi commented 3 years ago

Context

In my app, calling SpreeMultiVendor::Spree::Preferences in rails c results in NameError.

So I cannot execute any rake task. :sob:

# bin/rails c
Running via Spring preloader in process 276
Loading development environment (Rails 6.1.3)
[1] pry(main)> SpreeMultiVendor::Configuration
NameError: uninitialized constant SpreeMultiVendor::Spree::Preferences
from /usr/local/lib/ruby/gems/3.0.0/bundler/gems/spree_multi_vendor-bf37f0624cc1/app/models/spree_multi_vendor/configuration.rb:2:in `<module:SpreeMultiVendor>'

Expected Behavior

no errors.

Actual Behavior

NameError.(see above)

Possible Fix

  1. set config.eager_load=true and config.cache_classes = true (and stop spring)

Or

  1. Fork and patch this.
--- a/app/models/spree_multi_vendor/configuration.rb
+++ b/app/models/spree_multi_vendor/configuration.rb
@@ -1,5 +1,5 @@
 module SpreeMultiVendor
-  class Configuration < Spree::Preferences::Configuration
+  class Configuration < ::Spree::Preferences::Configuration
     DEFAULT_VENDORIZED_MODELS ||= %w[product variant stock_location shipping_method].freeze

    # Some example preferences are shown below, for more information visit:

Steps to Reproduce

For example, in spec/dummy (created by bundle exec rake test_app) in this repo.

  1. (bundle exec rake test_app)
  2. cd spec/dummy
  3. BUNDLE_GEMFILE=../../Gemfile bundle exec rails c
  4. Type SpreeMultiVendor::Spree::Preferences and hit Enter
[dummy]$ BUNDLE_GEMFILE=../../Gemfile bundle exec rails c
/Users/hoshino/go/src/github.com/route06/spree_multi_vendor/app/models/spree_multi_vendor/spree/order_decorator.rb:69: warning: already initialized constant SpreeMultiVendor::Spree::OrderDecorator::METHOD_NAMES
/Users/hoshino/go/src/github.com/route06/spree_multi_vendor/app/models/spree_multi_vendor/spree/order_decorator.rb:69: warning: previous definition of METHOD_NAMES was here
Loading development environment (Rails 6.1.3)
irb(main):001:0> SpreeMultiVendor::Configuration
Traceback (most recent call last):
        1: from (irb):1:in `<main>'
NameError (uninitialized constant SpreeMultiVendor::Spree::Preferences)

version

spree-contrib/master bf37f0624cc1a5f7a3b7431136cd8416a54fed60