spree_order_price_sync 0.60.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +9 -0
- data/LICENSE +23 -0
- data/README.markdown +9 -0
- data/Rakefile +75 -0
- data/Versionfile +11 -0
- data/app/models/price_observer.rb +16 -0
- data/lib/spree_order_price_sync.rb +18 -0
- data/lib/spree_order_price_sync_hooks.rb +3 -0
- data/lib/tasks/install.rake +25 -0
- data/lib/tasks/spree_order_price_sync.rake +1 -0
- data/spec/spec_helper.rb +30 -0
- data/spree_order_price_sync.gemspec +16 -0
- metadata +77 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
2
|
+
are permitted provided that the following conditions are met:
|
|
3
|
+
|
|
4
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
5
|
+
this list of conditions and the following disclaimer.
|
|
6
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
7
|
+
this list of conditions and the following disclaimer in the documentation
|
|
8
|
+
and/or other materials provided with the distribution.
|
|
9
|
+
* Neither the name of the Rails Dog LLC nor the names of its
|
|
10
|
+
contributors may be used to endorse or promote products derived from this
|
|
11
|
+
software without specific prior written permission.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
14
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
15
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
16
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
17
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
18
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
19
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
20
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
21
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
22
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
23
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.markdown
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Order Price Sync 0.60.x
|
|
2
|
+
================
|
|
3
|
+
|
|
4
|
+
This extension adds an observer that watches product and variant records for price changes.
|
|
5
|
+
When a price changes, all relevant line items in all active (unfinised) orders have their
|
|
6
|
+
prices changed accordingly, are saved, and the order is re-totaled and saved.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2011 Azimuth Internet Services, released under the New BSD License
|
data/Rakefile
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rake/testtask'
|
|
4
|
+
require 'rake/packagetask'
|
|
5
|
+
require 'rake/gempackagetask'
|
|
6
|
+
|
|
7
|
+
gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
|
|
8
|
+
if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
|
|
9
|
+
require 'bundler'
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
|
11
|
+
Bundler.setup
|
|
12
|
+
|
|
13
|
+
require 'rspec'
|
|
14
|
+
require 'rspec/core/rake_task'
|
|
15
|
+
RSpec::Core::RakeTask.new
|
|
16
|
+
|
|
17
|
+
require 'cucumber/rake/task'
|
|
18
|
+
Cucumber::Rake::Task.new do |t|
|
|
19
|
+
t.cucumber_opts = %w{--format progress}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
desc "Default Task"
|
|
24
|
+
task :default => [:spec, :cucumber ]
|
|
25
|
+
|
|
26
|
+
spec = eval(File.read('spree_order_price_sync.gemspec'))
|
|
27
|
+
|
|
28
|
+
Rake::GemPackageTask.new(spec) do |p|
|
|
29
|
+
p.gem_spec = spec
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
desc "Release to gemcutter"
|
|
33
|
+
task :release => :package do
|
|
34
|
+
require 'rake/gemcutter'
|
|
35
|
+
Rake::Gemcutter::Tasks.new(spec).define
|
|
36
|
+
Rake::Task['gem:push'].invoke
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
desc "Default Task"
|
|
40
|
+
task :default => [ :spec ]
|
|
41
|
+
|
|
42
|
+
desc "Regenerates a rails 3 app for testing"
|
|
43
|
+
task :test_app do
|
|
44
|
+
require '../spree/lib/generators/spree/test_app_generator'
|
|
45
|
+
class SpreeOrderPriceSyncTestAppGenerator < Spree::Generators::TestAppGenerator
|
|
46
|
+
|
|
47
|
+
def install_gems
|
|
48
|
+
inside "test_app" do
|
|
49
|
+
run 'bundle exec rake spree_core:install'
|
|
50
|
+
run 'bundle exec rake spree_order_price_sync:install'
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def migrate_db
|
|
55
|
+
run_migrations
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
protected
|
|
59
|
+
def full_path_for_local_gems
|
|
60
|
+
<<-gems
|
|
61
|
+
gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
|
|
62
|
+
gem 'spree_order_price_sync', :path => \'#{File.dirname(__FILE__)}\'
|
|
63
|
+
gems
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
SpreeOrderPriceSyncTestAppGenerator.start
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
namespace :test_app do
|
|
71
|
+
desc 'Rebuild test and cucumber databases'
|
|
72
|
+
task :rebuild_dbs do
|
|
73
|
+
system("cd spec/test_app && bundle exec rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
|
|
74
|
+
end
|
|
75
|
+
end
|
data/Versionfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# This file is used to designate compatibilty with different versions of Spree
|
|
2
|
+
# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
|
|
3
|
+
|
|
4
|
+
# Examples
|
|
5
|
+
#
|
|
6
|
+
# "0.50.x" => { :branch => "master" }
|
|
7
|
+
# "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
|
|
8
|
+
|
|
9
|
+
"0.60.x" => { :branch => "master" }
|
|
10
|
+
"0.11.x" => { :branch => "0.11-stable" }
|
|
11
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class PriceObserver < ActiveRecord::Observer
|
|
2
|
+
observe Product, Variant
|
|
3
|
+
|
|
4
|
+
def after_save(record)
|
|
5
|
+
inactive_states = YAML.load Spree::Config.get(:order_price_sync_inactive_states_list)
|
|
6
|
+
to_update = Order.all.reject{|o| inactive_states.include? o.state }.collect {|o| o.line_items }.flatten.select{|i| i.variant_id == record.id }
|
|
7
|
+
to_update.each do |l|
|
|
8
|
+
if l.price != record.price
|
|
9
|
+
l.price = record.price
|
|
10
|
+
l.save
|
|
11
|
+
l.order.update_totals
|
|
12
|
+
l.order.save
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'spree_core'
|
|
2
|
+
require 'spree_order_price_sync_hooks'
|
|
3
|
+
|
|
4
|
+
module SpreeOrderPriceSync
|
|
5
|
+
class Engine < Rails::Engine
|
|
6
|
+
|
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
|
8
|
+
|
|
9
|
+
def self.activate
|
|
10
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
|
|
11
|
+
Rails.env.production? ? require(c) : load(c)
|
|
12
|
+
end
|
|
13
|
+
@price_observer = PriceObserver.instance
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
config.to_prepare &method(:activate).to_proc
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
namespace :spree_order_price_sync do
|
|
2
|
+
desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
|
|
3
|
+
task :install do
|
|
4
|
+
Rake::Task['spree_order_price_sync:install:migrations'].invoke
|
|
5
|
+
Rake::Task['spree_order_price_sync:install:assets'].invoke
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
namespace :install do
|
|
9
|
+
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
|
|
10
|
+
task :migrations do
|
|
11
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'db')
|
|
12
|
+
destination = File.join(Rails.root, 'db')
|
|
13
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
|
|
17
|
+
task :assets do
|
|
18
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'public')
|
|
19
|
+
destination = File.join(Rails.root, 'public')
|
|
20
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
|
21
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# add custom rake tasks here
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
|
2
|
+
# from the project root directory.
|
|
3
|
+
ENV["RAILS_ENV"] ||= 'test'
|
|
4
|
+
require File.expand_path("../test_app/config/environment", __FILE__)
|
|
5
|
+
require 'rspec/rails'
|
|
6
|
+
|
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
|
8
|
+
# in ./support/ and its subdirectories.
|
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
10
|
+
|
|
11
|
+
RSpec.configure do |config|
|
|
12
|
+
# == Mock Framework
|
|
13
|
+
#
|
|
14
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
|
15
|
+
#
|
|
16
|
+
# config.mock_with :mocha
|
|
17
|
+
# config.mock_with :flexmock
|
|
18
|
+
# config.mock_with :rr
|
|
19
|
+
config.mock_with :rspec
|
|
20
|
+
|
|
21
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
|
22
|
+
|
|
23
|
+
#config.include Devise::TestHelpers, :type => :controller
|
|
24
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
|
25
|
+
# examples within a transaction, comment the following line or assign false
|
|
26
|
+
# instead of true.
|
|
27
|
+
config.use_transactional_fixtures = true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.platform = Gem::Platform::RUBY
|
|
3
|
+
s.name = 'spree_order_price_sync'
|
|
4
|
+
s.version = '0.60.1'
|
|
5
|
+
s.summary = 'Updates existing line items in unfinished orders when product prices change.'
|
|
6
|
+
s.description = ''
|
|
7
|
+
s.author = 'Christopher Maujean'
|
|
8
|
+
s.email = 'christopher@azimuthonline.com'
|
|
9
|
+
|
|
10
|
+
s.files = `git ls-files`.split("\n")
|
|
11
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
|
12
|
+
s.require_path = 'lib'
|
|
13
|
+
s.requirements << 'none'
|
|
14
|
+
|
|
15
|
+
s.add_dependency('spree_core', '>= 0.60.1')
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: spree_order_price_sync
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 0.60.1
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Christopher Maujean
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
|
|
13
|
+
date: 2011-07-08 00:00:00 -07:00
|
|
14
|
+
default_executable:
|
|
15
|
+
dependencies:
|
|
16
|
+
- !ruby/object:Gem::Dependency
|
|
17
|
+
name: spree_core
|
|
18
|
+
prerelease: false
|
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
20
|
+
none: false
|
|
21
|
+
requirements:
|
|
22
|
+
- - ">="
|
|
23
|
+
- !ruby/object:Gem::Version
|
|
24
|
+
version: 0.60.1
|
|
25
|
+
type: :runtime
|
|
26
|
+
version_requirements: *id001
|
|
27
|
+
description: ""
|
|
28
|
+
email: christopher@azimuthonline.com
|
|
29
|
+
executables: []
|
|
30
|
+
|
|
31
|
+
extensions: []
|
|
32
|
+
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
|
|
35
|
+
files:
|
|
36
|
+
- .gitignore
|
|
37
|
+
- LICENSE
|
|
38
|
+
- README.markdown
|
|
39
|
+
- Rakefile
|
|
40
|
+
- Versionfile
|
|
41
|
+
- app/models/price_observer.rb
|
|
42
|
+
- lib/spree_order_price_sync.rb
|
|
43
|
+
- lib/spree_order_price_sync_hooks.rb
|
|
44
|
+
- lib/tasks/install.rake
|
|
45
|
+
- lib/tasks/spree_order_price_sync.rake
|
|
46
|
+
- spec/spec_helper.rb
|
|
47
|
+
- spree_order_price_sync.gemspec
|
|
48
|
+
has_rdoc: true
|
|
49
|
+
homepage:
|
|
50
|
+
licenses: []
|
|
51
|
+
|
|
52
|
+
post_install_message:
|
|
53
|
+
rdoc_options: []
|
|
54
|
+
|
|
55
|
+
require_paths:
|
|
56
|
+
- lib
|
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
|
+
none: false
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: "0"
|
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
|
+
none: false
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: "0"
|
|
69
|
+
requirements:
|
|
70
|
+
- none
|
|
71
|
+
rubyforge_project:
|
|
72
|
+
rubygems_version: 1.6.2
|
|
73
|
+
signing_key:
|
|
74
|
+
specification_version: 3
|
|
75
|
+
summary: Updates existing line items in unfinished orders when product prices change.
|
|
76
|
+
test_files: []
|
|
77
|
+
|