spree_size_chart 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -0
- data/Gemfile +9 -0
- data/LICENSE +26 -0
- data/README.md +77 -0
- data/Rakefile +29 -0
- data/Versionfile +11 -0
- data/app/assets/javascripts/admin/spree_size_chart.js +1 -0
- data/app/assets/javascripts/spree/admin/size_charts.js +2 -0
- data/app/assets/javascripts/spree/admin/size_types.js +2 -0
- data/app/assets/javascripts/store/spree_size_chart.js +1 -0
- data/app/assets/stylesheets/admin/spree_size_chart.css +3 -0
- data/app/assets/stylesheets/spree/admin/size_charts.css.scss +3 -0
- data/app/assets/stylesheets/spree/admin/size_types.css.scss +3 -0
- data/app/assets/stylesheets/store/spree_size_chart.css +16 -0
- data/app/controllers/spree/admin/size_charts_controller.rb +24 -0
- data/app/controllers/spree/admin/size_types_controller.rb +12 -0
- data/app/helpers/spree/admin/size_charts_helper.rb +2 -0
- data/app/helpers/spree/admin/size_types_helper.rb +2 -0
- data/app/models/spree.rb +5 -0
- data/app/models/spree/product_decorator.rb +3 -0
- data/app/models/spree/size_chart.rb +72 -0
- data/app/models/spree/size_type.rb +11 -0
- data/app/models/spree/size_value.rb +7 -0
- data/app/overrides/add_product_tab.rb +6 -0
- data/app/overrides/add_to_show_product.rb +4 -0
- data/app/overrides/admin_configuration.rb +18 -0
- data/app/views/spree/admin/size_charts/_form.html.erb +28 -0
- data/app/views/spree/admin/size_charts/edit.html.erb +24 -0
- data/app/views/spree/admin/size_types/_form.html.erb +4 -0
- data/app/views/spree/admin/size_types/edit.html.erb +10 -0
- data/app/views/spree/admin/size_types/index.html.erb +30 -0
- data/app/views/spree/admin/size_types/new.html.erb +10 -0
- data/app/views/spree/shared/_size_chart.html.erb +31 -0
- data/config/locales/en.yml +6 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20120416191149_create_spree_size_charts.rb +11 -0
- data/db/migrate/20120416191216_create_spree_size_types.rb +15 -0
- data/db/migrate/20120416191257_create_spree_size_values.rb +12 -0
- data/db/migrate/20120421093828_add_unit_to_spree_size_charts.rb +5 -0
- data/lib/generators/spree_size_chart/install/install_generator.rb +29 -0
- data/lib/spree_size_chart.rb +2 -0
- data/lib/spree_size_chart/engine.rb +20 -0
- data/lib/spree_size_chart/version.rb +3 -0
- data/script/rails +5 -0
- data/spec/controllers/spree/admin/size_charts_controller_spec.rb +5 -0
- data/spec/controllers/spree/admin/size_types_controller_spec.rb +5 -0
- data/spec/factories.rb +15 -0
- data/spec/helpers/spree/admin/size_charts_helper_spec.rb +15 -0
- data/spec/helpers/spree/admin/size_types_helper_spec.rb +15 -0
- data/spec/models/spree/size_chart_spec.rb +78 -0
- data/spec/models/spree/size_type_spec.rb +5 -0
- data/spec/models/spree/size_value_spec.rb +5 -0
- data/spec/requests/spree_size_chart_spec.rb +69 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/support/shared_connection.rb +12 -0
- data/spec/support/url_helpers.rb +7 -0
- data/spree_size_chart.gemspec +32 -0
- metadata +215 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2012 [name of plugin creator]
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
13
|
+
endorse or promote products derived from this software without specific
|
14
|
+
prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
SpreeSizeChart
|
2
|
+
==============
|
3
|
+
|
4
|
+
SpreeSizeChart feature extracted from [http://www.hallyustyle.com](http://www.hallyustyle.com).
|
5
|
+
|
6
|
+
SpreeSizeChart is a spree extension helping your store to provide pertinent product information.
|
7
|
+
|
8
|
+
Example
|
9
|
+
-------
|
10
|
+
|
11
|
+
![Spree SizeChart Admin](http://i49.tinypic.com/27ybj8x.png)
|
12
|
+
|
13
|
+
![Spree SizeChart Store](http://i50.tinypic.com/wk2fs.png)
|
14
|
+
|
15
|
+
Installation
|
16
|
+
------------
|
17
|
+
|
18
|
+
To install SpreeSizeChart, just add the following to your Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'spree_size_chart', '~> 1.0.0'
|
22
|
+
```
|
23
|
+
|
24
|
+
Now, bundle up and run the generator:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
bundle
|
28
|
+
rails g spree_minicart:install
|
29
|
+
```
|
30
|
+
|
31
|
+
Customization
|
32
|
+
-------------
|
33
|
+
|
34
|
+
The SizeChart markup should let you customize the way you want your SizeChart by using Deface or overriding views/spree/shared/_size_chart_.html.erb in your spree app.
|
35
|
+
|
36
|
+
If you want to display yourself the size chart, just disable the deface :
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# disable size_chart, explicitly put in the view
|
40
|
+
Deface::Override.new( :virtual_path => "spree/products/show",
|
41
|
+
:name => "add_size_chart_to_show_product",
|
42
|
+
:replace => '',
|
43
|
+
:disabled => true)
|
44
|
+
```
|
45
|
+
|
46
|
+
See [Spree Guide](http://guides.spreecommerce.com/view_customization.html) for more information.
|
47
|
+
|
48
|
+
|
49
|
+
Todo
|
50
|
+
-------
|
51
|
+
|
52
|
+
- Better html markup and HTML test for customization
|
53
|
+
- Add translation to size type.
|
54
|
+
- Compatibilty Spree 1.1.X
|
55
|
+
|
56
|
+
Compatibility
|
57
|
+
------------
|
58
|
+
|
59
|
+
Tested under Spree 1.0.4
|
60
|
+
|
61
|
+
|
62
|
+
Testing
|
63
|
+
-------
|
64
|
+
|
65
|
+
Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
|
66
|
+
|
67
|
+
$ bundle
|
68
|
+
$ bundle exec rake test_app
|
69
|
+
$ bundle exec rspec spec
|
70
|
+
|
71
|
+
|
72
|
+
Contribute
|
73
|
+
----------
|
74
|
+
|
75
|
+
Pull requests for features and bug fix with tests are welcome.
|
76
|
+
|
77
|
+
Copyright (c) 2012 [Stephane BOUNMY], released under the New BSD License
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/packagetask'
|
4
|
+
require 'rubygems/package_task'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'spree/core/testing_support/common_rake'
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new
|
9
|
+
|
10
|
+
task :default => [:spec]
|
11
|
+
|
12
|
+
spec = eval(File.read('spree_size_chart.gemspec'))
|
13
|
+
|
14
|
+
Gem::PackageTask.new(spec) do |p|
|
15
|
+
p.gem_spec = spec
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Release to gemcutter"
|
19
|
+
task :release => :package do
|
20
|
+
require 'rake/gemcutter'
|
21
|
+
Rake::Gemcutter::Tasks.new(spec).define
|
22
|
+
Rake::Task['gem:push'].invoke
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Generates a dummy app for testing"
|
26
|
+
task :test_app do
|
27
|
+
ENV['LIB_NAME'] = 'spree_size_chart'
|
28
|
+
Rake::Task['common:test_app'].invoke
|
29
|
+
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.70.x" => { :branch => "master"}
|
7
|
+
# "0.60.x" => { :branch => "0-60-stable" }
|
8
|
+
# "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
|
9
|
+
|
10
|
+
"1.0.x" => { :branch => "1-0-stable" }
|
11
|
+
"1.1.x" => { :branch => "master" }
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require admin/spree_core
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require store/spree_core
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/*
|
2
|
+
*= require store/spree_core
|
3
|
+
*/
|
4
|
+
|
5
|
+
div#product-size-chart table tbody th {
|
6
|
+
text-align: left;
|
7
|
+
padding-left: 10px;
|
8
|
+
}
|
9
|
+
|
10
|
+
div#product-size-chart table tbody td {
|
11
|
+
text-align: center;
|
12
|
+
}
|
13
|
+
|
14
|
+
div#product-size-chart table tbody td, div#product-size-chart table tbody th {
|
15
|
+
vertical-align: middle;
|
16
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
class SizeChartsController < ResourceController
|
4
|
+
|
5
|
+
def edit
|
6
|
+
@product = Product.find_by_permalink params[:product_id]
|
7
|
+
@size_chart = @product.size_chart || @product.build_size_chart
|
8
|
+
end
|
9
|
+
|
10
|
+
def update
|
11
|
+
@product = Product.find_by_permalink params[:product_id]
|
12
|
+
if (@product.size_chart || @product.build_size_chart).update_attributes params[:size_chart]
|
13
|
+
flash[:notice] = "Size Chart successfully updated"
|
14
|
+
else
|
15
|
+
end
|
16
|
+
redirect_to edit_admin_product_size_chart_path(@product)
|
17
|
+
end
|
18
|
+
|
19
|
+
def collection_url
|
20
|
+
admin_product_size_chart_url(@product)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/app/models/spree.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Spree
|
2
|
+
class SizeChart < ActiveRecord::Base
|
3
|
+
UNITS = ['cm', 'inch']
|
4
|
+
|
5
|
+
belongs_to :option_type, :class_name => "Spree::OptionType"
|
6
|
+
belongs_to :product
|
7
|
+
has_many :option_values, :through => :option_type
|
8
|
+
has_and_belongs_to_many :size_types, :class_name => "Spree::SizeType", :join_table => "spree_size_charts_size_types"
|
9
|
+
has_many :size_values, :class_name => "Spree::SizeValue"
|
10
|
+
|
11
|
+
accepts_nested_attributes_for :size_values, :allow_destroy => true
|
12
|
+
attr_accessible :size_values_attributes, :size_type_ids, :unit, :option_type_id
|
13
|
+
|
14
|
+
def size_values_attributes_with_sanity_check=(attributes)
|
15
|
+
attributes.each_value do |attrs|
|
16
|
+
if attrs['value'].blank?
|
17
|
+
attrs.merge!('_destroy' => true)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
self.size_values_attributes_without_sanity_check = attributes
|
21
|
+
end
|
22
|
+
|
23
|
+
alias_method_chain :size_values_attributes=, :sanity_check
|
24
|
+
|
25
|
+
def find_size_values
|
26
|
+
@size_values = []
|
27
|
+
option_value_ids.each do |opt_value_id|
|
28
|
+
size_type_ids.each do |size_type_id|
|
29
|
+
if _size_value = find_or_initialize_size_value(opt_value_id, size_type_id) and !_size_value.new_record?
|
30
|
+
@size_values << _size_value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
@size_values
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def find_or_initialize_size_values
|
40
|
+
@size_values = []
|
41
|
+
option_value_ids.each do |opt_value_id|
|
42
|
+
size_type_ids.each do |size_type_id|
|
43
|
+
@size_values << find_or_initialize_size_value(opt_value_id, size_type_id)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
@size_values
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_or_initialize_size_value(opt_value_id, size_type_id)
|
51
|
+
(hash_size_values[opt_value_id] and hash_size_values[opt_value_id][size_type_id]) || size_values.build(:size_type_id => size_type_id, :option_value_id => opt_value_id)
|
52
|
+
end
|
53
|
+
|
54
|
+
def hash_size_values
|
55
|
+
return @hsize_values if @hsize_values
|
56
|
+
@hsize_values = {}
|
57
|
+
size_values(true).each do |size_val|
|
58
|
+
if @hsize_values[size_val.option_value_id]
|
59
|
+
@hsize_values[size_val.option_value_id].merge!(size_val.size_type_id => size_val)
|
60
|
+
else
|
61
|
+
@hsize_values[size_val.option_value_id] = { size_val.size_type_id => size_val }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
@hsize_values
|
65
|
+
end
|
66
|
+
|
67
|
+
def option_type_with_unit
|
68
|
+
"#{option_type.try(:presentation)} (#{unit})"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Deface::Override.new( :virtual_path => "spree/admin/shared/_product_tabs",
|
2
|
+
:name => "add_size_chart_product_tabs",
|
3
|
+
:insert_bottom => 'ul[data-hook="admin_product_tabs"].sidebar.product-menu',
|
4
|
+
:text => %Q{<li<%== ' class="active"' if current == 'Size Chart' %>>
|
5
|
+
<%= link_to t(:size_chart), edit_admin_product_size_chart_url(@product) %>
|
6
|
+
</li>})
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Deface::Override.new(:virtual_path => "spree/admin/shared/_configuration_menu",
|
2
|
+
:name => "add_size_chart_type_link_configuration_menu",
|
3
|
+
:insert_bottom => "[data-hook='admin_configurations_sidebar_menu']",
|
4
|
+
:text => %q{<%= configurations_sidebar_menu_item t("size_types"), admin_size_types_path %>},
|
5
|
+
:disabled => false)
|
6
|
+
|
7
|
+
|
8
|
+
Deface::Override.new(:virtual_path => "spree/admin/configurations/index",
|
9
|
+
:name => "add_size_types_to_configuration_menu",
|
10
|
+
:insert_bottom => "[data-hook='admin_configurations_menu']",
|
11
|
+
:text => %q{
|
12
|
+
<tr>
|
13
|
+
<td><%= link_to t("size_types"), admin_size_types_path %></td>
|
14
|
+
<td><%= t("size_types_description") %></td>
|
15
|
+
</tr>
|
16
|
+
},
|
17
|
+
:original => '2645fce66adc090d7ce0aa34f7cdfcaabf1be9f0',
|
18
|
+
:disabled => false)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<%= form.field_container :name do %>
|
2
|
+
<table>
|
3
|
+
<% unless form.object.new_record? %>
|
4
|
+
<% @i = 0 %>
|
5
|
+
<% @size_type_count = form.object.size_types.count %>
|
6
|
+
<tr>
|
7
|
+
<th><%= form.object.option_type.try(:presentation) %></th>
|
8
|
+
<% form.object.size_types.each do |type| %>
|
9
|
+
<th><%= type.name %></th>
|
10
|
+
<% end %>
|
11
|
+
</tr>
|
12
|
+
<%= form.fields_for :size_values, form.object.find_or_initialize_size_values do |value_form| %>
|
13
|
+
<% if @i == 0 %>
|
14
|
+
<%= "<tr>".html_safe %>
|
15
|
+
<th><%= form.object.option_values.find(value_form.object.option_value_id).name %></th>
|
16
|
+
<% end %>
|
17
|
+
<td>
|
18
|
+
<%= value_form.hidden_field :size_type_id %>
|
19
|
+
<%= value_form.hidden_field :option_value_id %>
|
20
|
+
<%= value_form.text_field :value %>
|
21
|
+
</td>
|
22
|
+
<%= "</tr>".html_safe if @i == @size_type_count - 1 %>
|
23
|
+
<% @i += 1 %>
|
24
|
+
<% @i = 0 if @i == @size_type_count %>
|
25
|
+
<% end %>
|
26
|
+
<% end %>
|
27
|
+
</table>
|
28
|
+
<% end %>
|