Skip to content
This repository has been archived by the owner on Feb 27, 2021. It is now read-only.

Store Credits subtract twice in non-production and non-development env for 1.3 stable branch. #47

Open
nemofang opened this issue Sep 14, 2013 · 3 comments

Comments

@nemofang
Copy link

This is an issue we met in our project when using this store credits extension. On our development env, all things worked fine. But when we run the app on QA envs. things goes mad. We always get store credits subtract twice. That means if u use $30 sc, it will subtract $60 from your remaining store credits.

After check the source code of sc extension, we find this is caused of the configuration inside spree_store_credits.rb. Inside the file, we have a condition statement use Rails env to configure the extension:

 def self.activate
      Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
        Rails.env == "production" ? require(c) : load(c)
      end
  end

We can change the condition statement to follow to fix this issue:

 def self.activate
      Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
        Rails.configuration.cache_classes ? require(c) : load(c)
      end
  end

Seems the require/load setting must be same as its host app of this extension.

@jasonfb
Copy link

jasonfb commented Dec 1, 2014

I've got a nasty little bug that shows up only in QA environments as well. I actually didn't test production (since my code isn't there yet), but my bug definitely shows up in QA + Staging environment but NOT development. I will post a separate issue.

@jasonfb
Copy link

jasonfb commented Dec 1, 2014

When debugging this I noticed that on the spree2-0 stable branch of this gem this file contains a Rails.env == "production" which either requires or loads the files in the gem. (Load will load the file twice, thus doing all kinds of things like attaching duplicitous event handlers when using class_eval).

https://github.com/spree-contrib/spree_store_credits/blob/2-0-stable/lib/spree_store_credits.rb

I am suspicious of this, of course, although I haven't actually identified it as my problem.

(if anyone ever tries to make an argument that it is EVER ok to use Rails.env to run things only one way in production, don't believe them. Never ever.)

@jasonfb
Copy link

jasonfb commented Feb 10, 2015

On Spree 2.1, this gem does more things inconsistently between environments. In our case, it is showing the store credit on all screens leading up to the "Complete" step but the adjustment seems to get knocked off during the complete step. This manifests in some environments but not others. Also it is inconsistent even within the environment where the symptom manifests -- sometimes it happens, sometime it does not.

AMENDED: I was wrong about the symptom described above, and therefore I was also wrong about our problem being an environment-specific problem. I do know for sure that Version 1.3 and 2.0 of this gem have a environment-specific problems because of the Rails.env == "production" check mentioned in my comment from Dec 1st 2014. However, this code has been removed as of 2-1-stable and therefore I no longer think version 2-1-stable and 2-2-stable have environment-specific problems.

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

No branches or pull requests

2 participants