spree_sale_products 0.60.0.RC1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/LICENSE +23 -0
- data/README +0 -0
- data/README.md +17 -0
- data/Rakefile +1 -0
- data/Versionfile +9 -0
- data/app/helpers/products_helper_decorator.rb +12 -0
- data/app/models/line_item_decorator.rb +5 -0
- data/app/models/order_decorator.rb +31 -0
- data/app/models/product_decorator.rb +9 -0
- data/app/models/variant_decorator.rb +5 -0
- data/app/views/admin/products/_product_price.html.erb +11 -0
- data/app/views/admin/products/_product_reduction_form_field.html.erb +5 -0
- data/app/views/admin/products/_products_list_item.html.erb +7 -0
- data/config/locales/en.yml +2 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20110617153542_add_reduction_to_products.rb +9 -0
- data/lib/float.rb +5 -0
- data/lib/spree_sale_products.rb +18 -0
- data/lib/spree_sale_products_hooks.rb +5 -0
- data/lib/tasks/install.rake +25 -0
- data/lib/tasks/spree_sale_products.rake +1 -0
- data/spec/spec_helper.rb +30 -0
- data/spree_sale_products.gemspec +18 -0
- metadata +86 -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
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Summary
|
2
|
+
=======
|
3
|
+
|
4
|
+
Provides a per product reduced price option calculated by percentage off. Price are rounded down e.g 50% off 15.99 = 7.99. Very early stages of dev and not tested yet.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
gem "spree_sale_products", :git => 'git://github.com/sebastyuiop/spree_sale_products.git'
|
10
|
+
|
11
|
+
bundle install
|
12
|
+
|
13
|
+
rake spree_sale_products:install
|
14
|
+
|
15
|
+
rake db:migrate
|
16
|
+
|
17
|
+
Copyright (c) 2011 sebastyuiop, released under the New BSD License
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/Versionfile
ADDED
@@ -0,0 +1,9 @@
|
|
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,0 +1,12 @@
|
|
1
|
+
ProductsHelper.class_eval do
|
2
|
+
def product_price(product_or_variant, options={})
|
3
|
+
options.assert_valid_keys(:format_as_currency, :show_vat_text, :show_calculated_price)
|
4
|
+
options.reverse_merge! :format_as_currency => true, :show_vat_text => Spree::Config[:show_price_inc_vat]
|
5
|
+
|
6
|
+
amount = options[:show_calculated_price] ? product_or_variant.calculated_price : product_or_variant.price
|
7
|
+
amount += Calculator::Vat.calculate_tax_on(product_or_variant) if Spree::Config[:show_price_inc_vat]
|
8
|
+
|
9
|
+
options.delete(:show_calculated_price)
|
10
|
+
options.delete(:format_as_currency) ? format_price(amount, options) : amount
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Order.class_eval do
|
2
|
+
def add_variant(variant, quantity = 1)
|
3
|
+
current_item = contains?(variant)
|
4
|
+
if current_item
|
5
|
+
current_item.quantity += quantity
|
6
|
+
current_item.save
|
7
|
+
else
|
8
|
+
current_item = LineItem.new(:quantity => quantity)
|
9
|
+
current_item.variant = variant
|
10
|
+
current_item.price = variant.calculated_price
|
11
|
+
self.line_items << current_item
|
12
|
+
end
|
13
|
+
|
14
|
+
# populate line_items attributes for additional_fields entries
|
15
|
+
# that have populate => [:line_item]
|
16
|
+
Variant.additional_fields.select{|f| !f[:populate].nil? && f[:populate].include?(:line_item) }.each do |field|
|
17
|
+
value = ""
|
18
|
+
|
19
|
+
if field[:only].nil? || field[:only].include?(:variant)
|
20
|
+
value = variant.send(field[:name].gsub(" ", "_").downcase)
|
21
|
+
elsif field[:only].include?(:product)
|
22
|
+
value = variant.product.send(field[:name].gsub(" ", "_").downcase)
|
23
|
+
end
|
24
|
+
current_item.update_attribute(field[:name].gsub(" ", "_").downcase, value)
|
25
|
+
end
|
26
|
+
|
27
|
+
current_item
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<p class="prices">
|
2
|
+
<%= t("price") %>
|
3
|
+
<br />
|
4
|
+
<% if @product.reduction_percentage.blank? %>
|
5
|
+
<span class="price selling"><%= product_price(@product) %></span>
|
6
|
+
<% else %>
|
7
|
+
<span class="price was">Was <%= product_price(@product) %></span>
|
8
|
+
<span class="price now">Now <%= product_price(@product, :show_calculated_price => true) %>!</span>
|
9
|
+
<span class="price reduction"><%= @product.reduction_percentage %>% OFF</span>
|
10
|
+
<% end %>
|
11
|
+
</p>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<%= link_to small_image(product), product %>
|
2
|
+
|
3
|
+
<% if product.reduction_percentage.blank? %>
|
4
|
+
<%= link_to raw(product.name + " <span class='price selling'>#{product_price(product)}</span>"), product, :class => 'info' %>
|
5
|
+
<% else %>
|
6
|
+
<%= link_to raw(product.name + " <span class='price was' style='text-decoration:line-through'>#{product_price(product)}</span> <span class='price now'>#{product_price(product, :show_calculated_price => true)}</span>"), product, :class => 'info' %>
|
7
|
+
<% end %>
|
data/config/routes.rb
ADDED
data/lib/float.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
require 'spree_sale_products_hooks'
|
3
|
+
require 'float'
|
4
|
+
|
5
|
+
module SpreeSaleProducts
|
6
|
+
class Engine < Rails::Engine
|
7
|
+
|
8
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
9
|
+
|
10
|
+
def self.activate
|
11
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
|
12
|
+
Rails.env.production? ? require(c) : load(c)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
config.to_prepare &method(:activate).to_proc
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
class SpreeSaleProductsHooks < Spree::ThemeSupport::HookListener
|
2
|
+
insert_after :admin_product_form_right, 'admin/products/product_reduction_form_field.html.erb'
|
3
|
+
replace :products_list_item, 'admin/products/products_list_item.html.erb'
|
4
|
+
replace :product_price, 'admin/products/product_price.html.erb'
|
5
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
namespace :spree_sale_products 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_sale_products:install:migrations'].invoke
|
5
|
+
Rake::Task['spree_sale_products: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,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.platform = Gem::Platform::RUBY
|
3
|
+
s.name = 'spree_sale_products'
|
4
|
+
s.version = '0.60.0.RC1'
|
5
|
+
s.summary = 'Allows a product to be marked as a sale product with discount'
|
6
|
+
s.description = 'Add (optional) gem description here'
|
7
|
+
s.required_ruby_version = '>= 1.8.7'
|
8
|
+
|
9
|
+
s.author = 'Seb Weston'
|
10
|
+
s.email = 'sebweston@gmail.com'
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.require_path = 'lib'
|
15
|
+
s.requirements << 'none'
|
16
|
+
|
17
|
+
s.add_dependency('spree_core', '>= 0.60.0.RC1')
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_sale_products
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.60.0.RC1
|
5
|
+
prerelease: 7
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Seb Weston
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: spree_core
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.60.0.RC1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.60.0.RC1
|
30
|
+
description: Add (optional) gem description here
|
31
|
+
email: sebweston@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- Versionfile
|
42
|
+
- app/helpers/products_helper_decorator.rb
|
43
|
+
- app/models/line_item_decorator.rb
|
44
|
+
- app/models/order_decorator.rb
|
45
|
+
- app/models/product_decorator.rb
|
46
|
+
- app/models/variant_decorator.rb
|
47
|
+
- app/views/admin/products/_product_price.html.erb
|
48
|
+
- app/views/admin/products/_product_reduction_form_field.html.erb
|
49
|
+
- app/views/admin/products/_products_list_item.html.erb
|
50
|
+
- config/locales/en.yml
|
51
|
+
- config/routes.rb
|
52
|
+
- db/migrate/20110617153542_add_reduction_to_products.rb
|
53
|
+
- lib/float.rb
|
54
|
+
- lib/spree_sale_products.rb
|
55
|
+
- lib/spree_sale_products_hooks.rb
|
56
|
+
- lib/tasks/install.rake
|
57
|
+
- lib/tasks/spree_sale_products.rake
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
- spree_sale_products.gemspec
|
60
|
+
homepage:
|
61
|
+
licenses: []
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.8.7
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>'
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.3.1
|
78
|
+
requirements:
|
79
|
+
- none
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.23
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Allows a product to be marked as a sale product with discount
|
85
|
+
test_files:
|
86
|
+
- spec/spec_helper.rb
|