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,9 +1,10 @@
1
- class Admin::AdjustmentsController < Admin::BaseController
2
- resource_controller
3
- belongs_to :order
4
-
5
- update.wants.html { redirect_to collection_url }
6
- create.wants.html { redirect_to collection_url }
7
- destroy.success.wants.js { @order.reload && render_js_for_destroy }
1
+ class Admin::AdjustmentsController < Admin::ResourceController
2
+ belongs_to :order, :find_by => :number
3
+ destroy.after :reload_order
8
4
 
5
+ private
6
+
7
+ def reload_order
8
+ @order.reload
9
+ end
9
10
  end
@@ -1,47 +1,15 @@
1
1
  class Admin::BaseController < Spree::BaseController
2
2
  ssl_required
3
3
 
4
- before_filter :check_alerts if Rails.env.production?
5
-
6
4
  helper :search
7
5
  helper 'admin/navigation'
8
6
  layout 'admin'
9
7
 
10
8
  protected
11
- def check_alerts
12
- return unless current_user and should_check_alerts?
13
-
14
- unless session.has_key? :alerts
15
- begin
16
- session[:alerts] = Spree::Alert.current(request.host)
17
- filter_dismissed_alerts
18
- Spree::Config.set :last_check_for_spree_alerts => DateTime.now.to_s
19
- rescue
20
- session[:alerts] = nil
21
- end
22
- end
23
- end
24
-
25
- def should_check_alerts?
26
- return false if not Spree::Config[:check_for_spree_alerts]
27
-
28
- last_check = Spree::Config[:last_check_for_spree_alerts]
29
- return true if last_check.blank?
30
-
31
- DateTime.parse(last_check) < 12.hours.ago
32
- end
33
-
34
- def filter_dismissed_alerts
35
- return unless session[:alerts]
36
- dismissed = (Spree::Config[:dismissed_spree_alerts] || '').split(',')
37
- session[:alerts].reject! { |a| dismissed.include? a.id.to_s }
38
- end
39
-
40
9
  def render_js_for_destroy
41
10
  render :partial => "/admin/shared/destroy"
42
- flash.notice = nil
43
11
  end
44
-
12
+
45
13
  # Index request for JSON needs to pass a CSRF token in order to prevent JSON Hijacking
46
14
  def check_json_authenticity
47
15
  return unless request.format.js? or request.format.json?
@@ -1,26 +1,2 @@
1
1
  class Admin::ConfigurationsController < Admin::BaseController
2
- before_filter :initialize_extension_links, :only => :index
3
-
4
- class << self
5
- def add_link(text, path, description)
6
- unless @@extension_links.any?{|link| link[:link_text] == text}
7
- @@extension_links << {
8
- :link => path,
9
- :link_text => text,
10
- :description => description,
11
- }
12
- end
13
- end
14
- end
15
-
16
- protected
17
-
18
- def initialize_extension_links
19
- @extension_links = [
20
- {:link => admin_shipping_methods_path, :link_text => t("shipping_methods"), :description => t("shipping_methods_description")},
21
- {:link => admin_shipping_categories_path, :link_text => t("shipping_categories"), :description => t("shipping_categories_description")},
22
- ] + @@extension_links
23
- end
24
-
25
- @@extension_links = []
26
2
  end
@@ -1,29 +1,10 @@
1
- class Admin::ImagesController < Admin::BaseController
2
- resource_controller
1
+ class Admin::ImagesController < Admin::ResourceController
3
2
  before_filter :load_data
4
3
 
5
- new_action.response do |wants|
6
- wants.html {render :action => :new, :layout => false}
7
- end
8
-
9
- create.response do |wants|
10
- wants.html {redirect_to admin_product_images_url(@product)}
11
- end
12
-
13
- update.response do |wants|
14
- wants.html {redirect_to admin_product_images_url(@product)}
15
- end
16
-
17
4
  create.before :set_viewable
18
5
  update.before :set_viewable
19
6
  destroy.before :destroy_before
20
7
 
21
- destroy.response do |wants|
22
- wants.html do
23
- render :text => ""
24
- end
25
- end
26
-
27
8
  def update_positions
28
9
  params[:positions].each do |id, index|
29
10
  Image.update_all(['position=?', index], ['id=?', id])
@@ -35,6 +16,10 @@ class Admin::ImagesController < Admin::BaseController
35
16
  end
36
17
 
37
18
  private
19
+
20
+ def location_after_save
21
+ admin_product_images_url(@product)
22
+ end
38
23
 
39
24
  def load_data
40
25
  @product = Product.find_by_permalink(params[:product_id])
@@ -47,18 +32,18 @@ class Admin::ImagesController < Admin::BaseController
47
32
  def set_viewable
48
33
  if params[:image].has_key? :viewable_id
49
34
  if params[:image][:viewable_id] == "All"
50
- object.viewable = @product
35
+ @image.viewable = @product
51
36
  else
52
- object.viewable_type = 'Variant'
53
- object.viewable_id = params[:image][:viewable_id]
37
+ @image.viewable_type = 'Variant'
38
+ @image.viewable_id = params[:image][:viewable_id]
54
39
  end
55
40
  else
56
- object.viewable = @product
41
+ @image.viewable = @product
57
42
  end
58
43
  end
59
44
 
60
45
  def destroy_before
61
- @viewable = object.viewable
46
+ @viewable = @image.viewable
62
47
  end
63
48
 
64
49
  end
@@ -1,46 +1,61 @@
1
1
  class Admin::LineItemsController < Admin::BaseController
2
- resource_controller
3
- belongs_to :order
4
2
 
5
- actions :all, :except => :index
3
+ before_filter :load_order
4
+ before_filter :load_line_item, :only => [:destroy, :update]
6
5
 
7
- create.flash nil
8
- update.flash nil
9
- destroy.flash nil
10
-
11
- #override r_c create action as we want to use order#add_variant instead of creating line_item
12
6
  def create
13
- load_object
14
7
  variant = Variant.find(params[:line_item][:variant_id])
15
-
16
- before :create
17
-
18
8
  @order.add_variant(variant, params[:line_item][:quantity].to_i)
19
9
 
20
10
  if @order.save
21
- after :create
22
- set_flash :create
23
- response_for :create
11
+ respond_to do |format|
12
+ format.html do
13
+ render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false
14
+ end
15
+ end
24
16
  else
25
- after :create_fails
26
- set_flash :create_fails
27
- response_for :create_fails
28
17
  end
18
+ end
29
19
 
20
+ def destroy
21
+ if @line_item.destroy
22
+ respond_to do |format|
23
+ format.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false }
24
+ end
25
+ else
26
+ respond_to do |format|
27
+ format.html do
28
+ render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false
29
+ end
30
+ end
31
+ end
30
32
  end
31
33
 
32
- destroy.success.wants.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false }
33
- destroy.failure.wants.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false }
34
+ def new
35
+ respond_to do |format|
36
+ format.html { render :action => :new, :layout => false }
37
+ end
38
+ end
34
39
 
35
- new_action.response do |wants|
36
- wants.html {render :action => :new, :layout => false}
40
+ def update
41
+ if @line_item.update_attributes(params[:line_item])
42
+ respond_to do |format|
43
+ format.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false}
44
+ end
45
+ else
46
+ respond_to do |format|
47
+ format.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false}
48
+ end
49
+ end
37
50
  end
38
51
 
39
- create.response do |wants|
40
- wants.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false}
52
+
53
+ def load_order
54
+ @order = Order.find_by_number! params[:order_id]
41
55
  end
42
56
 
43
- update.success.wants.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false}
44
- update.failure.wants.html { render :partial => "admin/orders/form", :locals => {:order => @order.reload}, :layout => false}
57
+ def load_line_item
58
+ @line_item = @order.line_items.find params[:id]
59
+ end
45
60
 
46
61
  end
@@ -1,13 +1,8 @@
1
- class Admin::MailMethodsController < Admin::BaseController
2
- resource_controller
3
-
1
+ class Admin::MailMethodsController < Admin::ResourceController
4
2
  after_filter :initialize_mail_settings
5
3
 
6
- update.wants.html { redirect_to collection_url }
7
- create.wants.html { redirect_to collection_url }
8
-
9
4
  private
10
5
  def initialize_mail_settings
11
6
  Spree::MailSettings.init
12
7
  end
13
- end
8
+ end
@@ -1,8 +1,5 @@
1
- class Admin::OptionTypesController < Admin::BaseController
2
- resource_controller
3
-
4
- before_filter :load_object, :only => [:selected, :available, :remove]
5
- belongs_to :product
1
+ class Admin::OptionTypesController < Admin::ResourceController
2
+ before_filter :load_product, :only => [:selected, :available, :remove]
6
3
 
7
4
  def available
8
5
  set_available_option_types
@@ -31,22 +28,6 @@ class Admin::OptionTypesController < Admin::BaseController
31
28
  end
32
29
  end
33
30
 
34
- new_action.response do |wants|
35
- wants.html {render :action => :new, :layout => !request.xhr?}
36
- end
37
-
38
- # redirect to index (instead of r_c default of show view)
39
- create.response do |wants|
40
- wants.html {redirect_to edit_object_url}
41
- end
42
-
43
- # redirect to index (instead of r_c default of show view)
44
- update.response do |wants|
45
- wants.html {redirect_to collection_url}
46
- end
47
-
48
- destroy.success.wants.js { render_js_for_destroy }
49
-
50
31
  # AJAX method for selecting an existing option type and associating with the current product
51
32
  def select
52
33
  @product = Product.find_by_param!(params[:product_id])
@@ -57,7 +38,22 @@ class Admin::OptionTypesController < Admin::BaseController
57
38
  set_available_option_types
58
39
  end
59
40
 
41
+ protected
42
+
43
+ def location_after_save
44
+ if @option_type.created_at == @option_type.updated_at
45
+ edit_admin_option_type_url(@option_type)
46
+ else
47
+ admin_option_types_url
48
+ end
49
+ end
50
+
51
+
60
52
  private
53
+ def load_product
54
+ @product = Product.find_by_param!(params[:product_id])
55
+ end
56
+
61
57
  def set_available_option_types
62
58
  @available_option_types = OptionType.all
63
59
  selected_option_types = []
@@ -1,37 +1,86 @@
1
1
  class Admin::OrdersController < Admin::BaseController
2
2
  require 'spree/gateway_error'
3
- resource_controller
4
3
  before_filter :initialize_txn_partials
5
4
  before_filter :initialize_order_events
6
- before_filter :load_object, :only => [:fire, :resend, :history, :user]
7
- before_filter :ensure_line_items, :only => [:update]
5
+ before_filter :load_order, :only => [:fire, :resend, :history, :user]
8
6
 
9
- update do
10
- flash nil
11
- wants.html do
12
- if !@order.line_items.empty?
13
- unless @order.complete?
7
+ def index
8
+ params[:search] ||= {}
9
+ params[:search][:completed_at_is_not_null] ||= '1' if Spree::Config[:show_only_complete_orders_by_default]
10
+ @show_only_completed = params[:search][:completed_at_is_not_null].present?
11
+ params[:search][:meta_sort] ||= @show_only_completed ? 'completed_at.desc' : 'created_at.desc'
12
+
13
+ @search = Order.metasearch(params[:search])
14
+
15
+ if !params[:search][:created_at_greater_than].blank?
16
+ params[:search][:created_at_greater_than] = Time.zone.parse(params[:search][:created_at_greater_than]).beginning_of_day rescue ""
17
+ end
18
+
19
+ if !params[:search][:created_at_less_than].blank?
20
+ params[:search][:created_at_less_than] = Time.zone.parse(params[:search][:created_at_less_than]).end_of_day rescue ""
21
+ end
22
+
23
+ if @show_only_completed
24
+ params[:search][:completed_at_greater_than] = params[:search].delete(:created_at_greater_than)
25
+ params[:search][:completed_at_less_than] = params[:search].delete(:created_at_less_than)
26
+ end
14
27
 
15
- if params[:order].key?(:email)
16
- @order.shipping_method = @order.available_shipping_methods(:front_end).first
28
+ @orders = Order.metasearch(params[:search]).paginate(
29
+ :include => [:user, :shipments, :payments],
30
+ :per_page => Spree::Config[:orders_per_page],
31
+ :page => params[:page])
32
+ end
33
+
34
+ def show
35
+ load_order
36
+ end
37
+
38
+ def new
39
+ @order = Order.create
40
+ end
41
+
42
+ def edit
43
+ load_order
44
+ end
45
+
46
+ def update
47
+ return_path = nil
48
+ load_order
49
+ if @order.update_attributes(params[:order]) && @order.line_items.present?
50
+ unless @order.complete?
51
+
52
+ if params[:order].key?(:email)
53
+ shipping_method = @order.available_shipping_methods(:front_end).first
54
+ if shipping_method
55
+ @order.shipping_method = shipping_method
17
56
  @order.create_shipment!
18
- redirect_to edit_admin_order_shipment_path(@order, @order.shipment)
57
+ return_path = edit_admin_order_shipment_path(@order, @order.shipment)
19
58
  else
20
- redirect_to user_admin_order_path(@order)
59
+ flash[:error] = t('errors.messages.no_shipping_methods_available')
60
+ return_path = user_admin_order_path(@order)
21
61
  end
22
-
23
62
  else
24
- redirect_to admin_order_path(@order)
63
+ return_path = user_admin_order_path(@order)
25
64
  end
65
+
26
66
  else
27
- render :action => :new
67
+ return_path = admin_order_path(@order)
68
+ end
69
+ else
70
+ @order.errors.add(:line_items, t('errors.messages.blank'))
71
+ end
72
+
73
+ respond_to do |format|
74
+ format.html do
75
+ if return_path
76
+ redirect_to return_path
77
+ else
78
+ render :action => :edit
79
+ end
28
80
  end
29
81
  end
30
82
  end
31
83
 
32
- def new
33
- @order = @object = Order.create
34
- end
35
84
 
36
85
  def fire
37
86
  # TODO - possible security check here but right now any admin can before any transition (and the state machine
@@ -61,35 +110,9 @@ class Admin::OrdersController < Admin::BaseController
61
110
 
62
111
  private
63
112
 
64
- def object
65
- @object ||= Order.find_by_number(params[:id], :include => :adjustments) if params[:id]
66
- return @object || current_order
67
- end
68
-
69
- def collection
70
- params[:search] ||= {}
71
- @show_only_completed = params[:search][:completed_at_is_not_null].present?
72
- params[:search][:meta_sort] ||= @show_only_completed ? 'completed_at.desc' : 'created_at.desc'
73
-
74
- @search = Order.metasearch(params[:search])
75
-
76
- if !params[:search][:created_at_greater_than].blank?
77
- params[:search][:created_at_greater_than] = Time.zone.parse(params[:search][:created_at_greater_than]).beginning_of_day rescue ""
78
- end
79
-
80
- if !params[:search][:created_at_less_than].blank?
81
- params[:search][:created_at_less_than] = Time.zone.parse(params[:search][:created_at_less_than]).end_of_day rescue ""
82
- end
83
-
84
- if @show_only_completed
85
- params[:search][:completed_at_greater_than] = params[:search].delete(:created_at_greater_than)
86
- params[:search][:completed_at_less_than] = params[:search].delete(:created_at_less_than)
87
- end
88
-
89
- @collection = Order.metasearch(params[:search]).paginate(
90
- :include => [:user, :shipments, :payments],
91
- :per_page => Spree::Config[:orders_per_page],
92
- :page => params[:page])
113
+ def load_order
114
+ @order ||= Order.find_by_number(params[:id], :include => :adjustments) if params[:id]
115
+ @order
93
116
  end
94
117
 
95
118
  # Allows extensions to add new forms of payment to provide their own display of transactions
@@ -102,12 +125,4 @@ class Admin::OrdersController < Admin::BaseController
102
125
  @order_events = %w{cancel resume}
103
126
  end
104
127
 
105
- def ensure_line_items
106
- load_object
107
- if @order.line_items.empty?
108
- @order.errors.add(:line_items, t('errors.messages.blank'))
109
- render :edit
110
- end
111
- end
112
-
113
128
  end