radiant-shop_variants-extension 0.1.2 → 0.1.3
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/VERSION +1 -1
- data/app/controllers/admin/shop/products/variants_controller.rb +35 -1
- data/app/models/shop_product_variant.rb +13 -3
- data/config/routes.rb +2 -2
- data/db/migrate/20110330100134_add_position_to_product_variant.rb +17 -0
- data/lib/shop_variants/controllers/products_controller.rb +5 -1
- data/lib/shop_variants/models/product.rb +2 -2
- data/lib/shop_variants/tags/product_variant.rb +5 -1
- data/public/javascripts/admin/extensions/shop/variants/edit.js +21 -1
- data/radiant-shop_variants-extension.gemspec +4 -3
- metadata +7 -6
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
@@ -2,7 +2,7 @@ class Admin::Shop::Products::VariantsController < Admin::ResourceController
|
|
2
2
|
|
3
3
|
model_class ShopProductVariant
|
4
4
|
|
5
|
-
before_filter :find_product
|
5
|
+
before_filter :find_product, :except => [:sort]
|
6
6
|
|
7
7
|
def create
|
8
8
|
notice = 'Successfully created variant.'
|
@@ -29,6 +29,40 @@ class Admin::Shop::Products::VariantsController < Admin::ResourceController
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
# PUT /admin/shop/products/1/variants/sort
|
33
|
+
# PUT /admin/shop/products/1/variants/sort.js
|
34
|
+
# PUT /admin/shop/products/1/variants/sort.json AJAX and HTML
|
35
|
+
#----------------------------------------------------------------------------
|
36
|
+
def sort
|
37
|
+
notice = 'Successfully sorted Variants.'
|
38
|
+
error = 'Could not sort Variants.'
|
39
|
+
begin
|
40
|
+
@shop_product = ShopProduct.find(params[:product_id])
|
41
|
+
|
42
|
+
@variants = CGI::parse(params[:variants])['variants[]']
|
43
|
+
@variants.each_with_index do |id, index|
|
44
|
+
ShopProductVariant.find(id).update_attributes!({ :position => index+1 })
|
45
|
+
end
|
46
|
+
|
47
|
+
respond_to do |format|
|
48
|
+
format.html {
|
49
|
+
redirect_to edit_admin_shop_product_path(@shop_product)
|
50
|
+
}
|
51
|
+
format.js { render :partial => '/admin/shop/products/edit/shared/variant', :collection => @shop_product.variants }
|
52
|
+
format.json { render :json => @shop_product.variants.to_json }
|
53
|
+
end
|
54
|
+
rescue
|
55
|
+
respond_to do |format|
|
56
|
+
format.html {
|
57
|
+
flash[:error] = error
|
58
|
+
redirect_to edit_admin_shop_product_path(@shop_product)
|
59
|
+
}
|
60
|
+
format.js { render :text => error, :status => :unprocessable_entity }
|
61
|
+
format.json { render :json => { :error => error }, :status => :unprocessable_entity }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
32
66
|
def destroy
|
33
67
|
notice = 'Successfully destroyed variant.'
|
34
68
|
error = 'Could not destroy variant.'
|
@@ -1,7 +1,9 @@
|
|
1
1
|
class ShopProductVariant < ActiveRecord::Base
|
2
2
|
|
3
3
|
belongs_to :product, :class_name => 'ShopProduct', :foreign_key => :product_id
|
4
|
-
|
4
|
+
acts_as_list :scope => :product
|
5
|
+
default_scope :order => :position
|
6
|
+
|
5
7
|
validates_presence_of :product
|
6
8
|
validates_presence_of :name
|
7
9
|
validates_uniqueness_of :name, :scope => :product_id
|
@@ -14,6 +16,10 @@ class ShopProductVariant < ActiveRecord::Base
|
|
14
16
|
has_many :discountables, :class_name => 'ShopDiscountable', :foreign_key => :discounted_id
|
15
17
|
has_many :discounts, :class_name => 'ShopDiscount', :through => :discountables
|
16
18
|
|
19
|
+
def name
|
20
|
+
%{#{product.name} #{self[:name]}}
|
21
|
+
end
|
22
|
+
|
17
23
|
# Returns the price of the variant plus the product price
|
18
24
|
def price
|
19
25
|
price = product.price
|
@@ -25,7 +31,11 @@ class ShopProductVariant < ActiveRecord::Base
|
|
25
31
|
|
26
32
|
# Returns a mixed sku of product and variant name
|
27
33
|
def sku
|
28
|
-
|
34
|
+
sku = nil
|
35
|
+
if self[:name].present?
|
36
|
+
sku = %{#{product.sku}-#{self[:name].gsub(/[^a-zA-Z0-9_]/,"_")}}
|
37
|
+
end
|
38
|
+
sku
|
29
39
|
end
|
30
40
|
|
31
41
|
# Returns slug of the product
|
@@ -41,4 +51,4 @@ class ShopProductVariant < ActiveRecord::Base
|
|
41
51
|
product.to_param
|
42
52
|
end
|
43
53
|
|
44
|
-
end
|
54
|
+
end
|
data/config/routes.rb
CHANGED
@@ -4,7 +4,7 @@ ActionController::Routing::Routes.draw do |map|
|
|
4
4
|
admin.namespace :shop, :member => { :remove => :get } do |shop|
|
5
5
|
|
6
6
|
shop.resources :products, :except => :new, :collection => { :sort => :put } do |product|
|
7
|
-
product.resources :variants, :controller => 'products/variants', :only => [ :create, :destroy]
|
7
|
+
product.resources :variants, :controller => 'products/variants', :only => [ :create, :destroy], :collection => { :sort => :put }
|
8
8
|
product.resources :variant_templates, :controller => 'products/variant_templates', :only => [ :update ]
|
9
9
|
end
|
10
10
|
shop.resources :variants
|
@@ -13,4 +13,4 @@ ActionController::Routing::Routes.draw do |map|
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddPositionToProductVariant < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :shop_product_variants, :position, :integer
|
4
|
+
|
5
|
+
ShopProduct.find_each do |p|
|
6
|
+
i = 1
|
7
|
+
p.variants.find_each do |v|
|
8
|
+
v.update_attribute(:position, i)
|
9
|
+
i += 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
remove_column :shop_product_variants, :position
|
16
|
+
end
|
17
|
+
end
|
@@ -34,6 +34,10 @@ module ShopVariants
|
|
34
34
|
:name => 'admin_shop_product_variant_path',
|
35
35
|
:path => admin_shop_product_variant_path(@shop_product, ':id')
|
36
36
|
}
|
37
|
+
@routes << {
|
38
|
+
:name => 'sort_admin_shop_product_variants_path',
|
39
|
+
:path => sort_admin_shop_product_variants_path(@shop_product)
|
40
|
+
}
|
37
41
|
end
|
38
42
|
|
39
43
|
end
|
@@ -41,4 +45,4 @@ module ShopVariants
|
|
41
45
|
|
42
46
|
end
|
43
47
|
end
|
44
|
-
end
|
48
|
+
end
|
@@ -4,7 +4,7 @@ module ShopVariants
|
|
4
4
|
|
5
5
|
def self.included(base)
|
6
6
|
base.class_eval do
|
7
|
-
has_many :variants, :class_name => 'ShopProductVariant', :foreign_key => :product_id, :dependent => :destroy, :order =>
|
7
|
+
has_many :variants, :class_name => 'ShopProductVariant', :foreign_key => :product_id, :dependent => :destroy, :order => :position
|
8
8
|
|
9
9
|
accepts_nested_attributes_for :variants
|
10
10
|
end
|
@@ -12,4 +12,4 @@ module ShopVariants
|
|
12
12
|
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -33,7 +33,11 @@ module ShopVariants
|
|
33
33
|
tag.expand if tag.locals.shop_product_variant.present?
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
tag 'shop:product:variant:name' do |tag|
|
37
|
+
tag.locals.shop_product_variant[:name]
|
38
|
+
end
|
39
|
+
|
40
|
+
[:id, :sku].each do |symbol|
|
37
41
|
desc %{ outputs the #{symbol} of the current shop variant }
|
38
42
|
tag "shop:product:variant:#{symbol}" do |tag|
|
39
43
|
tag.locals.shop_product_variant.send(symbol)
|
@@ -10,6 +10,26 @@ document.observe("dom:loaded", function() {
|
|
10
10
|
var ShopVariantEdit = Class.create({
|
11
11
|
|
12
12
|
initialize: function() {
|
13
|
+
this.variantsSort();
|
14
|
+
},
|
15
|
+
|
16
|
+
variantsSort: function(element) {
|
17
|
+
var route = shop.getRoute('sort_admin_shop_product_variants_path');
|
18
|
+
|
19
|
+
Sortable.create('variants', {
|
20
|
+
constraint: false,
|
21
|
+
overlap: 'horizontal',
|
22
|
+
containment: ['variants'],
|
23
|
+
onUpdate: function(element) {
|
24
|
+
new Ajax.Request(route, {
|
25
|
+
method: 'put',
|
26
|
+
parameters: {
|
27
|
+
'product_id': $('shop_product_id').value,
|
28
|
+
'variants': Sortable.serialize('variants')
|
29
|
+
}
|
30
|
+
});
|
31
|
+
}.bind(this)
|
32
|
+
})
|
13
33
|
},
|
14
34
|
|
15
35
|
variantRemove: function(element) {
|
@@ -35,4 +55,4 @@ var ShopVariantEdit = Class.create({
|
|
35
55
|
}
|
36
56
|
}
|
37
57
|
|
38
|
-
});
|
58
|
+
});
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{radiant-shop_variants-extension}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dirk Kelly"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-03-30}
|
13
13
|
s.description = %q{RadiantShop: Create variants of products, with alternative prices}
|
14
14
|
s.email = %q{dk@dirkkelly.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -53,6 +53,7 @@ Gem::Specification.new do |s|
|
|
53
53
|
"config/routes.rb",
|
54
54
|
"cucumber.yml",
|
55
55
|
"db/migrate/20101015162238_setup_shop_variants.rb",
|
56
|
+
"db/migrate/20110330100134_add_position_to_product_variant.rb",
|
56
57
|
"features/support/env.rb",
|
57
58
|
"features/support/paths.rb",
|
58
59
|
"lib/radiant-shop_variants-extension.rb",
|
@@ -81,7 +82,7 @@ Gem::Specification.new do |s|
|
|
81
82
|
]
|
82
83
|
s.homepage = %q{https://github.com/thefrontiergroup/radiant-shop_variants-extension}
|
83
84
|
s.require_paths = ["lib"]
|
84
|
-
s.rubygems_version = %q{1.
|
85
|
+
s.rubygems_version = %q{1.5.3}
|
85
86
|
s.summary = %q{Shop Variants Extension for Radiant CMS}
|
86
87
|
s.test_files = [
|
87
88
|
"spec/controllers/admin/shop/products/variant_templates_controller_spec.rb",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-shop_variants-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dirk Kelly
|
@@ -15,11 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-30 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
type: :runtime
|
23
22
|
name: radiant-shop-extension
|
24
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
@@ -31,6 +30,7 @@ dependencies:
|
|
31
30
|
- 0
|
32
31
|
version: "0"
|
33
32
|
prerelease: false
|
33
|
+
type: :runtime
|
34
34
|
requirement: *id001
|
35
35
|
description: "RadiantShop: Create variants of products, with alternative prices"
|
36
36
|
email: dk@dirkkelly.com
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- config/routes.rb
|
79
79
|
- cucumber.yml
|
80
80
|
- db/migrate/20101015162238_setup_shop_variants.rb
|
81
|
+
- db/migrate/20110330100134_add_position_to_product_variant.rb
|
81
82
|
- features/support/env.rb
|
82
83
|
- features/support/paths.rb
|
83
84
|
- lib/radiant-shop_variants-extension.rb
|
@@ -133,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
134
|
requirements: []
|
134
135
|
|
135
136
|
rubyforge_project:
|
136
|
-
rubygems_version: 1.
|
137
|
+
rubygems_version: 1.5.3
|
137
138
|
signing_key:
|
138
139
|
specification_version: 3
|
139
140
|
summary: Shop Variants Extension for Radiant CMS
|