spree_core 0.50.4 → 0.60.0.RC1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/app/controllers/admin/adjustments_controller.rb +8 -7
  2. data/app/controllers/admin/base_controller.rb +1 -33
  3. data/app/controllers/admin/configurations_controller.rb +0 -24
  4. data/app/controllers/admin/images_controller.rb +10 -25
  5. data/app/controllers/admin/line_items_controller.rb +41 -26
  6. data/app/controllers/admin/mail_methods_controller.rb +2 -7
  7. data/app/controllers/admin/option_types_controller.rb +17 -21
  8. data/app/controllers/admin/orders_controller.rb +70 -55
  9. data/app/controllers/admin/payment_methods_controller.rb +33 -22
  10. data/app/controllers/admin/payments_controller.rb +25 -27
  11. data/app/controllers/admin/product_groups_controller.rb +22 -20
  12. data/app/controllers/admin/product_properties_controller.rb +2 -6
  13. data/app/controllers/admin/product_scopes_controller.rb +24 -20
  14. data/app/controllers/admin/products_controller.rb +20 -26
  15. data/app/controllers/admin/properties_controller.rb +2 -20
  16. data/app/controllers/admin/prototypes_controller.rb +5 -33
  17. data/app/controllers/admin/resource_controller.rb +221 -0
  18. data/app/controllers/admin/return_authorizations_controller.rb +3 -9
  19. data/app/controllers/admin/shipments_controller.rb +68 -35
  20. data/app/controllers/admin/shipping_categories_controller.rb +1 -15
  21. data/app/controllers/admin/shipping_methods_controller.rb +6 -12
  22. data/app/controllers/admin/states_controller.rb +16 -21
  23. data/app/controllers/admin/tax_categories_controller.rb +1 -12
  24. data/app/controllers/admin/tax_rates_controller.rb +2 -12
  25. data/app/controllers/admin/taxonomies_controller.rb +11 -12
  26. data/app/controllers/admin/taxons_controller.rb +74 -53
  27. data/app/controllers/admin/trackers_controller.rb +1 -6
  28. data/app/controllers/admin/users_controller.rb +36 -35
  29. data/app/controllers/admin/variants_controller.rb +7 -22
  30. data/app/controllers/admin/zones_controller.rb +12 -25
  31. data/app/controllers/checkout_controller.rb +2 -6
  32. data/app/controllers/orders_controller.rb +0 -1
  33. data/app/controllers/products_controller.rb +12 -16
  34. data/app/controllers/taxons_controller.rb +8 -15
  35. data/app/helpers/admin/navigation_helper.rb +4 -0
  36. data/app/models/address.rb +1 -1
  37. data/app/models/app_configuration.rb +2 -3
  38. data/app/models/product.rb +1 -2
  39. data/app/models/product_group.rb +8 -8
  40. data/app/models/product_scope.rb +1 -1
  41. data/app/models/shipping_method.rb +6 -2
  42. data/app/models/tax_rate.rb +1 -1
  43. data/app/views/admin/general_settings/edit.html.erb +10 -15
  44. data/app/views/admin/general_settings/show.html.erb +5 -5
  45. data/app/views/admin/option_types/{new.html.erb → new.erb} +0 -0
  46. data/app/views/admin/orders/_form.html.erb +0 -1
  47. data/app/views/admin/orders/edit.html.erb +2 -2
  48. data/app/views/admin/orders/index.html.erb +2 -2
  49. data/app/views/admin/payment_methods/edit.html.erb +1 -1
  50. data/app/views/admin/payments/new.html.erb +2 -2
  51. data/app/views/admin/payments/show.html.erb +3 -3
  52. data/app/views/admin/product_groups/index.html.erb +1 -1
  53. data/app/views/admin/product_scopes/create.js.erb +3 -3
  54. data/app/views/admin/product_scopes/destroy.js.erb +2 -2
  55. data/app/views/admin/products/{new.html.erb → new.erb} +0 -0
  56. data/app/views/admin/properties/{new.html.erb → new.erb} +0 -0
  57. data/app/views/admin/prototypes/{new.html.erb → new.erb} +0 -0
  58. data/app/views/admin/shared/_product_tabs.html.erb +1 -1
  59. data/app/views/admin/shared/_tabs.html.erb +1 -1
  60. data/app/views/admin/shipments/edit.html.erb +3 -3
  61. data/app/views/admin/shipments/index.html.erb +1 -1
  62. data/app/views/admin/shipments/new.html.erb +1 -1
  63. data/app/views/admin/states/{new.html.erb → new.erb} +0 -0
  64. data/app/views/admin/tax_categories/edit.html.erb +1 -1
  65. data/app/views/admin/taxonomies/{edit.html.erb → edit.erb} +0 -0
  66. data/app/views/admin/taxons/edit.html.erb +1 -1
  67. data/app/views/admin/variants/{new.html.erb → new.erb} +0 -0
  68. data/app/views/admin/zones/index.html.erb +2 -3
  69. data/app/views/checkout/_address.html.erb +2 -2
  70. data/app/views/layouts/admin.html.erb +0 -1
  71. data/app/views/products/_thumbnails.html.erb +2 -2
  72. data/app/views/shared/_admin_head.html.erb +5 -5
  73. data/app/views/shared/_order_details.html.erb +1 -1
  74. data/app/views/states/index.js.erb +1 -1
  75. data/config/initializers/spree.rb +2 -0
  76. data/config/locales/en.yml +12 -9
  77. data/config/routes.rb +2 -6
  78. data/lib/scopes/product.rb +5 -8
  79. data/lib/spree/preference_access.rb +2 -2
  80. data/lib/spree_base.rb +1 -1
  81. data/lib/spree_core.rb +1 -1
  82. data/lib/spree_core/action_callbacks.rb +26 -0
  83. data/lib/spree_core/version.rb +1 -1
  84. data/lib/tasks/taxon.rake +1 -1
  85. data/public/javascripts/admin.js +0 -6
  86. data/public/javascripts/admin/address_states.js +5 -5
  87. data/public/javascripts/application.js +2 -2
  88. data/public/stylesheets/admin/admin.css +0 -29
  89. data/public/stylesheets/screen.css +1 -0
  90. metadata +97 -79
  91. data/app/models/spree/alert.rb +0 -13
  92. data/app/views/account/login.html.erb +0 -4
  93. data/app/views/admin/configurations/new.html.erb +0 -13
  94. data/app/views/admin/payments/_card_form.html.erb +0 -49
  95. data/app/views/admin/shared/_alert.html.erb +0 -6
  96. data/lib/spree_core/find_by_param.rb +0 -119
@@ -1,31 +1,42 @@
1
- class Admin::PaymentMethodsController < Admin::BaseController
2
- resource_controller
1
+ class Admin::PaymentMethodsController < Admin::ResourceController
2
+ skip_before_filter :load_resource, :only => [:create]
3
3
  before_filter :load_data
4
4
 
5
- update.before :update_before
5
+ def create
6
+ @payment_method = params[:payment_method][:type].constantize.new(params[:payment_method])
7
+ @object = @payment_method
8
+ invoke_callbacks(:create, :before)
9
+ if @payment_method.save
10
+ invoke_callbacks(:create, :after)
11
+ flash[:notice] = I18n.t(:successfully_created, :resource => I18n.t(:payment_method))
12
+ respond_with(@payment_method, :location => edit_admin_payment_method_path(@payment_method))
13
+ else
14
+ invoke_callbacks(:create, :fails)
15
+ render :new
16
+ end
17
+ end
6
18
 
7
- update.wants.html { redirect_to edit_object_url }
8
- create.wants.html { redirect_to edit_object_url }
19
+ def update
20
+ invoke_callbacks(:update, :before)
21
+ payment_method_type = params[:payment_method].delete(:type)
22
+ if @payment_method['type'].to_s != payment_method_type
23
+ @payment_method.update_attribute(:type, payment_method_type)
24
+ @payment_method = PaymentMethod.find(params[:id])
25
+ end
26
+ payment_method_params = params[@payment_method.class.name.underscore.gsub("/", "_")] || {}
27
+ if @payment_method.update_attributes(params[:payment_method].merge(payment_method_params))
28
+ invoke_callbacks(:update, :after)
29
+ flash[:notice] = I18n.t(:successfully_updated, :resource => I18n.t(:payment_method))
30
+ respond_with(@payment_method, :location => edit_admin_payment_method_path(@payment_method))
31
+ else
32
+ invoke_callbacks(:update, :fails)
33
+ render :edit
34
+ end
35
+ end
9
36
 
10
37
  private
11
- def build_object
12
- if params[:payment_method] && params[:payment_method][:type]
13
- @object ||= params[:payment_method][:type].constantize.send parent? ? :build : :new, object_params
14
- else
15
- @object ||= end_of_association_chain.send parent? ? :build : :new, object_params
16
- end
17
- end
18
38
 
19
39
  def load_data
20
- @providers = Gateway.providers
21
- end
22
-
23
- def update_before
24
- if params[:payment_method] && params[:payment_method][:type] && @object['type'].to_s != params[:payment_method][:type]
25
- @object.update_attribute(:type, params[:payment_method][:type])
26
-
27
- load_object
28
- end
29
- @object.update_attributes params[@object.class.name.underscore.gsub("/", "_")]
40
+ @providers = Gateway.providers.sort{|p1, p2| p1.name <=> p2.name }
30
41
  end
31
42
  end
@@ -1,12 +1,21 @@
1
1
  class Admin::PaymentsController < Admin::BaseController
2
+ before_filter :load_order, :only => [:create, :new, :index, :fire]
3
+ before_filter :load_payment, :except => [:create, :new, :index]
2
4
  before_filter :load_data
3
- before_filter :load_amount, :except => :country_changed
4
- resource_controller
5
- belongs_to :order
5
+
6
+ def index
7
+ @payments = @order.payments
8
+ end
9
+
10
+ def new
11
+ @payment = @order.payments.build
12
+ end
6
13
 
7
14
  def create
8
- build_object
9
- load_object
15
+ @payment = @order.payments.build(object_params)
16
+ if @payment.payment_method.is_a?(Gateway) && @payment.payment_method.payment_profiles_supported? && params[:card].present? and params[:card] != 'new'
17
+ @payment.source = Creditcard.find_by_id(params[:card])
18
+ end
10
19
 
11
20
  begin
12
21
  unless @payment.save
@@ -16,8 +25,8 @@ class Admin::PaymentsController < Admin::BaseController
16
25
 
17
26
  if @order.completed?
18
27
  @payment.process!
19
- set_flash :create
20
- redirect_to collection_path
28
+ flash[:notice] = I18n.t(:successfully_created, :resource => 'payment')
29
+ redirect_to admin_order_payments_path(@order)
21
30
  else
22
31
  #This is the first payment (admin created order)
23
32
  until @order.completed?
@@ -29,13 +38,12 @@ class Admin::PaymentsController < Admin::BaseController
29
38
 
30
39
  rescue Spree::GatewayError => e
31
40
  flash[:error] = "#{e.message}"
32
- redirect_to new_object_path
41
+ redirect_to new_admin_payment_path(@order)
33
42
  end
34
43
  end
35
44
 
36
45
  def fire
37
46
  # TODO: consider finer-grained control for this type of action (right now anyone in admin role can perform)
38
- load_object
39
47
  return unless event = params[:e] and @payment.payment_source
40
48
  if @payment.payment_source.send("#{event}", @payment)
41
49
  flash.notice = t('payment_updated')
@@ -45,16 +53,11 @@ class Admin::PaymentsController < Admin::BaseController
45
53
  rescue Spree::GatewayError => ge
46
54
  flash[:error] = "#{ge.message}"
47
55
  ensure
48
- redirect_to collection_path
56
+ redirect_to admin_order_payments_path(@order)
49
57
  end
50
58
 
51
59
  private
52
60
 
53
- def object
54
- @object ||= Payment.find(param) unless param.nil?
55
- @object
56
- end
57
-
58
61
  def object_params
59
62
  if params[:payment] and params[:payment_source] and source_params = params.delete(:payment_source)[params[:payment][:payment_method_id]]
60
63
  params[:payment][:source_attributes] = source_params
@@ -63,27 +66,22 @@ class Admin::PaymentsController < Admin::BaseController
63
66
  end
64
67
 
65
68
  def load_data
66
- load_object
69
+ @amount = params[:amount] || load_order.total
67
70
  @payment_methods = PaymentMethod.available(:back_end)
68
- if object and object.payment_method
69
- @payment_method = object.payment_method
71
+ if @payment and @payment.payment_method
72
+ @payment_method = @payment.payment_method
70
73
  else
71
74
  @payment_method = @payment_methods.first
72
75
  end
73
76
  @previous_cards = @order.creditcards.with_payment_profile
74
77
  end
75
78
 
76
- def load_amount
77
- @amount = params[:amount] || @order.total
79
+ def load_order
80
+ @order ||= Order.find_by_number! params[:order_id]
78
81
  end
79
82
 
80
- def build_object
81
- @object = model.new(object_params)
82
- @object.order = parent_object
83
- if @object.payment_method.is_a?(Gateway) and @object.payment_method.payment_profiles_supported? and params[:card].present? and params[:card] != 'new'
84
- @object.source = Creditcard.find_by_id(params[:card])
85
- end
86
- @object
83
+ def load_payment
84
+ @payment ||= Payment.find params[:id]
87
85
  end
88
86
 
89
87
  end
@@ -1,26 +1,35 @@
1
- class Admin::ProductGroupsController < Admin::BaseController
2
- resource_controller
3
-
4
- create.response do |wants|
5
- wants.html { redirect_to edit_object_path }
6
- end
7
- update.response do |wants|
8
- wants.html { redirect_to edit_object_path }
9
- wants.js { render :action => 'update', :layout => false}
10
- end
11
-
1
+ class Admin::ProductGroupsController < Admin::ResourceController
2
+ before_filter :patch_params, :only => [:update]
3
+
12
4
  def preview
13
5
  @product_group = ProductGroup.new(params[:product_group])
14
6
  @product_group.name = "for_preview"
15
7
  render :partial => 'preview', :layout => false
16
8
  end
17
9
 
10
+ protected
18
11
 
12
+ def find_resource
13
+ ProductGroup.find_by_permalink(params[:id])
14
+ end
15
+
16
+ def location_after_save
17
+ edit_admin_product_group_path(@product_group)
18
+ end
19
+
20
+ def collection
21
+ params[:search] ||= {}
22
+ params[:search][:meta_sort] ||= "name.asc"
23
+ @search = super.metasearch(params[:search])
24
+ @collection = @search.paginate( :per_page => Spree::Config[:per_page],
25
+ :page => params[:page])
26
+ end
27
+
19
28
  private
20
29
 
21
30
  # Consolidate argument arrays for nested product_scope attributes
22
31
  # Necessary for product scopes with multiple arguments
23
- def object_params
32
+ def patch_params
24
33
  if params["product_group"] and params["product_group"]["product_scopes_attributes"].is_a?(Array)
25
34
  params["product_group"]["product_scopes_attributes"] = params["product_group"]["product_scopes_attributes"].group_by {|a| a["id"]}.map do |scope_id, attrs|
26
35
  a = { "id" => scope_id, "arguments" => attrs.map{|a| a["arguments"] }.flatten }
@@ -30,15 +39,8 @@ class Admin::ProductGroupsController < Admin::BaseController
30
39
  a
31
40
  end
32
41
  end
33
- params["product_group"]
34
42
  end
35
43
 
36
- def collection
37
- params[:search] ||= {}
38
- params[:search][:meta_sort] ||= "name.desc"
39
- @search = ProductGroup.metasearch(params[:search])
40
- @collection = @search.paginate( :per_page => Spree::Config[:per_page],
41
- :page => params[:page])
42
- end
44
+
43
45
 
44
46
  end
@@ -1,11 +1,7 @@
1
- class Admin::ProductPropertiesController < Admin::BaseController
2
- resource_controller
1
+ class Admin::ProductPropertiesController < Admin::ResourceController
2
+ belongs_to :product, :find_by => :permalink
3
3
  before_filter :find_properties
4
4
 
5
- # note: we're using attribute_fu to manage the product_properties so the products controller will be
6
- # doing most of the work
7
- belongs_to :product
8
-
9
5
  private
10
6
 
11
7
  def find_properties
@@ -1,27 +1,31 @@
1
1
  class Admin::ProductScopesController < Admin::BaseController
2
2
  helper 'admin/product_groups'
3
-
4
- resource_controller
5
-
6
- belongs_to :product_group
7
-
8
- actions :create, :destroy
9
3
 
10
- destroy.after :update_memberships
11
-
12
- create.response do |wants|
13
- wants.html { redirect_to edit_admin_product_group_path(parent_object) }
14
- wants.js { render :action => 'create', :layout => false}
15
- end
16
- destroy.response do |wants|
17
- wants.html { redirect_to edit_admin_product_group_path(parent_object) }
18
- wants.js { render :action => 'destroy', :layout => false}
4
+ def create
5
+ @product_group = ProductGroup.find_by_permalink(params[:product_group_id])
6
+ @product_scope = @product_group.product_scopes.build(params[:product_scope])
7
+ if @product_scope.save
8
+ respond_to do |format|
9
+ format.html { redirect_to edit_admin_product_group_path(@product_group) }
10
+ format.js { render :layout => false }
11
+ end
12
+ else
13
+ render :new
14
+ end
19
15
  end
20
16
 
21
- private
17
+ def destroy
18
+ @product_scope = ProductScope.find(params[:id])
19
+ if @product_scope.destroy
20
+ @product_group = @product_scope.product_group
21
+ @product_group.update_memberships
22
+ respond_to do |format|
23
+ format.html { redirect_to edit_admin_product_group_path(@product_group) }
24
+ format.js { render :layout => false }
25
+ end
26
+ else
27
+ redirect_to edit_admin_product_group_path(@product_scope.product_group)
28
+ end
29
+ end
22
30
 
23
- def update_memberships
24
- object.product_group.update_memberships
25
- end
26
-
27
31
  end
@@ -1,28 +1,13 @@
1
- class Admin::ProductsController < Admin::BaseController
2
- resource_controller
1
+ class Admin::ProductsController < Admin::ResourceController
3
2
  before_filter :check_json_authenticity, :only => :index
4
3
  before_filter :load_data, :except => :index
5
-
6
- index.response do |wants|
7
- wants.html { render :action => :index }
8
- wants.json { render :json => json_data }
9
- end
10
-
11
- new_action.response do |wants|
12
- wants.html {render :action => :new, :layout => !request.xhr?}
13
- end
14
-
15
4
  update.before :update_before
16
5
 
17
- create.response do |wants|
18
- # go to edit form after creating as new product
19
- wants.html {redirect_to edit_admin_product_url(@product) }
20
- end
21
-
22
- update.response do |wants|
23
- # override the default redirect behavior of r_c
24
- # need to reload Product in case name / permalink has changed
25
- wants.html {redirect_to edit_admin_product_url(@product) }
6
+ def index
7
+ respond_to do |format|
8
+ format.html
9
+ format.json { render :json => json_data }
10
+ end
26
11
  end
27
12
 
28
13
  # override the destory method to set deleted_at value
@@ -49,7 +34,6 @@ class Admin::ProductsController < Admin::BaseController
49
34
  end
50
35
 
51
36
  def clone
52
- load_object
53
37
  @new = @product.duplicate
54
38
 
55
39
  if @new.save
@@ -60,7 +44,17 @@ class Admin::ProductsController < Admin::BaseController
60
44
 
61
45
  redirect_to edit_admin_product_url(@new)
62
46
  end
63
-
47
+
48
+ protected
49
+
50
+ def find_resource
51
+ Product.find_by_permalink(params[:id])
52
+ end
53
+
54
+ def location_after_save
55
+ edit_admin_product_url(@product)
56
+ end
57
+
64
58
  # Allow different formats of json data to suit different ajax calls
65
59
  def json_data
66
60
  json_format = params[:json_format] or 'default'
@@ -88,7 +82,7 @@ class Admin::ProductsController < Admin::BaseController
88
82
  end
89
83
 
90
84
  params[:search][:meta_sort] ||= "name.asc"
91
- @search = end_of_association_chain.metasearch(params[:search])
85
+ @search = super.metasearch(params[:search])
92
86
 
93
87
  pagination_options = {:include => {:variants => [:images, :option_values]},
94
88
  :per_page => Spree::Config[:admin_products_per_page],
@@ -98,10 +92,10 @@ class Admin::ProductsController < Admin::BaseController
98
92
  else
99
93
  includes = [{:variants => [:images, {:option_values => :option_type}]}, :master, :images]
100
94
 
101
- @collection = end_of_association_chain.where(["name LIKE ?", "%#{params[:q]}%"])
95
+ @collection = super.where(["name #{LIKE} ?", "%#{params[:q]}%"])
102
96
  @collection = @collection.includes(includes).limit(params[:limit] || 10)
103
97
 
104
- tmp = end_of_association_chain.where(["variants.sku LIKE ?", "%#{params[:q]}%"])
98
+ tmp = super.where(["variants.sku #{LIKE} ?", "%#{params[:q]}%"])
105
99
  tmp = tmp.includes(:variants_including_master).limit(params[:limit] || 10)
106
100
  @collection.concat(tmp)
107
101
 
@@ -1,27 +1,9 @@
1
- class Admin::PropertiesController < Admin::BaseController
2
- resource_controller
3
-
4
- before_filter :load_object, :only => :filtered
5
- belongs_to :product
1
+ class Admin::PropertiesController < Admin::ResourceController
6
2
 
3
+ # Looks like this action is unused
7
4
  def filtered
8
5
  @properties = Property.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%").order(:name)
9
6
  render :template => "admin/properties/filtered.html.erb", :layout => false
10
7
  end
11
8
 
12
- new_action.response do |wants|
13
- wants.html {render :action => :new, :layout => !request.xhr? }
14
- end
15
-
16
- # redirect to index (instead of r_c default of show view)
17
- update.response do |wants|
18
- wants.html {redirect_to collection_url}
19
- end
20
-
21
- # redirect to index (instead of r_c default of show view)
22
- create.response do |wants|
23
- wants.html {redirect_to collection_url}
24
- end
25
-
26
- destroy.success.wants.js { render_js_for_destroy }
27
9
  end
@@ -1,5 +1,4 @@
1
- class Admin::PrototypesController < Admin::BaseController
2
- resource_controller
1
+ class Admin::PrototypesController < Admin::ResourceController
3
2
  after_filter :set_habtm_associations, :only => [:create, :update]
4
3
 
5
4
  helper 'admin/product_properties'
@@ -12,41 +11,14 @@ class Admin::PrototypesController < Admin::BaseController
12
11
  end
13
12
 
14
13
  def select
15
- load_object
14
+ @prototype ||= Prototype.find(params[:id])
16
15
  @prototype_properties = @prototype.properties
17
16
  end
18
17
 
19
- new_action.response do |wants|
20
- wants.html {
21
- render :action => :new, :layout => !request.xhr?
22
- }
23
- end
24
-
25
- # redirect to index (instead of r_c default of show view)
26
- update.response do |wants|
27
- wants.html {redirect_to collection_url}
28
- end
29
-
30
- # redirect to index (instead of r_c default of show view)
31
- create.response do |wants|
32
- wants.html {redirect_to collection_url}
33
- end
34
-
35
- destroy.success.wants.js { render_js_for_destroy }
36
-
37
18
  private
19
+
38
20
  def set_habtm_associations
39
- object.property_ids = params[:property][:id] if params[:property]
40
- object.option_type_ids = params[:option_type][:id] if params[:option_type]
41
- end
42
-
43
- def specified_rights(type)
44
- rights = []
45
- key = "#{type}_ids".to_sym
46
- params[:permission][key] ||= []
47
- params[:permission][key].each do |id|
48
- rights << type.classify.constantize.find(id)
49
- end
50
- rights
21
+ @prototype.property_ids = params[:property][:id] if params[:property]
22
+ @prototype.option_type_ids = params[:option_type][:id] if params[:option_type]
51
23
  end
52
24
  end