spree_core 0.60.0.RC1 → 0.60.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/app/controllers/admin/line_items_controller.rb +12 -13
  2. data/app/controllers/admin/orders_controller.rb +11 -3
  3. data/app/controllers/admin/payment_methods_controller.rb +3 -3
  4. data/app/controllers/admin/payments_controller.rb +12 -5
  5. data/app/controllers/admin/product_groups_controller.rb +1 -1
  6. data/app/controllers/admin/product_scopes_controller.rb +12 -8
  7. data/app/controllers/admin/products_controller.rb +7 -7
  8. data/app/controllers/admin/properties_controller.rb +3 -1
  9. data/app/controllers/admin/prototypes_controller.rb +4 -2
  10. data/app/controllers/admin/reports_controller.rb +5 -1
  11. data/app/controllers/admin/resource_controller.rb +40 -31
  12. data/app/controllers/admin/return_authorizations_controller.rb +1 -1
  13. data/app/controllers/admin/shipments_controller.rb +7 -8
  14. data/app/controllers/admin/states_controller.rb +3 -3
  15. data/app/controllers/admin/taxonomies_controller.rb +5 -2
  16. data/app/controllers/admin/taxons_controller.rb +39 -18
  17. data/app/controllers/admin/users_controller.rb +5 -5
  18. data/app/controllers/admin/variants_controller.rb +4 -4
  19. data/app/controllers/admin/zones_controller.rb +3 -2
  20. data/app/controllers/checkout_controller.rb +6 -5
  21. data/app/controllers/content_controller.rb +8 -2
  22. data/app/controllers/orders_controller.rb +8 -5
  23. data/app/controllers/products_controller.rb +9 -5
  24. data/app/controllers/spree/base_controller.rb +1 -0
  25. data/app/controllers/taxons_controller.rb +5 -1
  26. data/app/helpers/admin/taxons_helper.rb +14 -1
  27. data/app/helpers/spree/base_helper.rb +2 -1
  28. data/app/models/app_configuration.rb +1 -0
  29. data/app/models/creditcard.rb +1 -1
  30. data/app/views/admin/orders/history.html.erb +1 -1
  31. data/app/views/admin/reports/index.html.erb +3 -3
  32. data/app/views/admin/taxons/available.js.erb +2 -2
  33. data/app/views/admin/taxons/selected.html.erb +1 -0
  34. data/app/views/orders/show.html.erb +10 -12
  35. data/app/views/products/show.html.erb +1 -1
  36. data/app/views/taxons/show.html.erb +1 -1
  37. data/config/locales/en.yml +1 -3
  38. data/config/routes.rb +1 -0
  39. data/lib/product_filters.rb +2 -2
  40. data/lib/spree_base.rb +1 -0
  41. data/lib/spree_core.rb +6 -0
  42. data/lib/spree_core/ext/hash.rb +75 -0
  43. data/lib/spree_core/spree_custom_responder.rb +29 -0
  44. data/lib/spree_core/spree_respond_with.rb +57 -0
  45. data/lib/spree_core/version.rb +1 -1
  46. data/public/javascripts/taxonomy.js +8 -4
  47. data/public/stylesheets/admin/admin-reset.css +2 -0
  48. metadata +20 -22
@@ -7,7 +7,7 @@ class Admin::ReturnAuthorizationsController < Admin::ResourceController
7
7
  def fire
8
8
  @return_authorization.send("#{params[:e]}!")
9
9
  flash.notice = t('return_authorization_updated')
10
- redirect_to :back
10
+ respond_with(@return_authorization) { |format| format.html { redirect_to :back } }
11
11
  end
12
12
 
13
13
  protected
@@ -23,11 +23,11 @@ class Admin::ShipmentsController < Admin::BaseController
23
23
  assign_inventory_units
24
24
  if @shipment.save
25
25
  flash[:notice] = I18n.t(:successfully_created, :resource => 'shipment')
26
- respond_with(@object) do |format|
26
+ respond_with(@shipment) do |format|
27
27
  format.html { redirect_to edit_admin_order_shipment_path(@order, @shipment) }
28
28
  end
29
29
  else
30
- render :action => 'new'
30
+ respond_with(@shipment) { |format| format.html { render :action => 'new' } }
31
31
  end
32
32
  end
33
33
 
@@ -43,22 +43,20 @@ class Admin::ShipmentsController < Admin::BaseController
43
43
  @order.special_instructions = object_params[:special_instructions] if Spree::Config[:shipping_instructions]
44
44
  @order.shipping_method = @order.shipment.shipping_method
45
45
  @order.save
46
-
46
+
47
47
  flash[:notice] = I18n.t(:successfully_updated, :resource => I18n.t('shipment'))
48
48
  return_path = @order.completed? ? edit_admin_order_shipment_path(@order, @shipment) : admin_order_adjustments_path(@order)
49
49
  respond_with(@object) do |format|
50
50
  format.html { redirect_to return_path }
51
51
  end
52
52
  else
53
- render :action => 'edit'
53
+ respond_with(@shipment) { |format| format.html { render :action => 'edit' } }
54
54
  end
55
55
  end
56
56
 
57
57
  def destroy
58
58
  @shipment.destroy
59
- respond_to do |format|
60
- format.js { render_js_for_destroy }
61
- end
59
+ respond_with(@shipment) { |format| format.js { render_js_for_destroy } }
62
60
  end
63
61
 
64
62
  def fire
@@ -67,7 +65,8 @@ class Admin::ShipmentsController < Admin::BaseController
67
65
  else
68
66
  flash[:error] = t('cannot_perform_operation')
69
67
  end
70
- redirect_to :back
68
+
69
+ respond_with(@shipment) { |format| format.html { redirect_to :back } }
71
70
  end
72
71
 
73
72
  private
@@ -3,17 +3,17 @@ class Admin::StatesController < Admin::ResourceController
3
3
  before_filter :load_data
4
4
 
5
5
  def index
6
- respond_to do |format|
6
+ respond_with(@collection) do |format|
7
7
  format.html
8
8
  format.js { render :partial => 'state_list.html.erb' }
9
9
  end
10
10
  end
11
11
 
12
12
  protected
13
-
13
+
14
14
  def location_after_save
15
15
  admin_country_states_url(@country)
16
- end
16
+ end
17
17
 
18
18
  def collection
19
19
  super.order(:name)
@@ -1,11 +1,14 @@
1
1
  class Admin::TaxonomiesController < Admin::ResourceController
2
+ respond_to :json, :only => [:get_children]
2
3
 
3
4
  def get_children
4
5
  @taxons = Taxon.find(params[:parent_id]).children
6
+
7
+ respond_with(@taxons)
5
8
  end
6
-
9
+
7
10
  private
8
-
11
+
9
12
  def location_after_save
10
13
  if @taxonomy.created_at == @taxonomy.updated_at
11
14
  edit_admin_taxonomy_url(@taxonomy)
@@ -1,14 +1,29 @@
1
1
  class Admin::TaxonsController < Admin::BaseController
2
2
  include Railslove::Plugins::FindByParam::SingletonMethods
3
3
 
4
+ respond_to :html, :json, :js
5
+
4
6
  def create
5
7
  @taxonomy = Taxonomy.find(params[:taxonomy_id])
6
8
  @taxon = @taxonomy.taxons.build(params[:taxon])
7
9
  if @taxon.save
8
- render :text => @taxon
10
+ respond_with(@taxon) do |format|
11
+ format.json {render :json => @taxon.to_json }
12
+ end
9
13
  else
10
14
  flash[:error] = I18n.t('errors.messages.could_not_create_taxon')
11
- redirect_to @taxonomy ? edit_admin_taxonomy_url(@taxonomy) : admin_taxonomies_url
15
+ respond_with(@taxon) do |format|
16
+ format.html { redirect_to @taxonomy ? edit_admin_taxonomy_url(@taxonomy) : admin_taxonomies_url }
17
+ end
18
+ end
19
+ end
20
+
21
+ def update
22
+ update_before
23
+ update_after
24
+ respond_with(@taxon) do |format|
25
+ format.html { redirect_to edit_admin_taxonomy_url(@taxonomy) }
26
+ format.json { render :json => @taxon.to_json }
12
27
  end
13
28
  end
14
29
 
@@ -16,6 +31,8 @@ class Admin::TaxonsController < Admin::BaseController
16
31
  @taxonomy = Taxonomy.find(params[:taxonomy_id])
17
32
  @taxon = @taxonomy.taxons.find(params[:id])
18
33
  @permalink_part = @taxon.permalink.split("/").last
34
+
35
+ respond_with(:admin, @taxon)
19
36
  end
20
37
 
21
38
  def update
@@ -80,7 +97,7 @@ class Admin::TaxonsController < Admin::BaseController
80
97
  end
81
98
  end
82
99
 
83
- respond_to do |format|
100
+ respond_with(@taxon) do |format|
84
101
  format.html {redirect_to edit_admin_taxonomy_url(@taxonomy) }
85
102
  format.json {render :json => @taxon.to_json }
86
103
  end
@@ -89,28 +106,22 @@ class Admin::TaxonsController < Admin::BaseController
89
106
  def destroy
90
107
  @taxon = Taxon.find(params[:id])
91
108
  @taxon.destroy
92
- respond_to do |format|
93
- format.html { render :text => '' }
94
- format.js { render_js_for_destroy }
95
- end
109
+ respond_with(@taxon) { |format| format.json { render :json => '' } }
96
110
  end
97
111
 
98
112
  def selected
99
113
  @product = load_product
100
114
  @taxons = @product.taxons
115
+
116
+ respond_with(:admin, @taxons)
101
117
  end
102
118
 
103
119
  def available
104
120
  @product = load_product
105
- if params[:q].blank?
106
- @available_taxons = []
107
- else
108
- @available_taxons = Taxon.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%")
109
- end
110
- @available_taxons.delete_if { |taxon| @product.taxons.include?(taxon) }
111
- respond_to do |format|
112
- format.js {render :layout => false}
113
- end
121
+ @taxons = params[:q].blank? ? [] : Taxon.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%")
122
+ @taxons.delete_if { |taxon| @product.taxons.include?(taxon) }
123
+
124
+ respond_with(:admin, @taxons)
114
125
  end
115
126
 
116
127
  def remove
@@ -119,7 +130,8 @@ class Admin::TaxonsController < Admin::BaseController
119
130
  @product.taxons.delete(@taxon)
120
131
  @product.save
121
132
  @taxons = @product.taxons
122
- render_js_for_destroy
133
+
134
+ respond_with(@taxon) { |format| format.js { render_js_for_destroy } }
123
135
  end
124
136
 
125
137
  def select
@@ -128,7 +140,16 @@ class Admin::TaxonsController < Admin::BaseController
128
140
  @product.taxons << @taxon
129
141
  @product.save
130
142
  @taxons = @product.taxons
131
- render :layout => false
143
+
144
+ respond_with(:admin, @taxons)
145
+ end
146
+
147
+ def batch_select
148
+ @product = load_product
149
+ @taxons = params[:taxon_ids].map{|id| Taxon.find(id)}.compact
150
+ @product.taxons = @taxons
151
+ @product.save
152
+ redirect_to selected_admin_product_taxons_url(@product)
132
153
  end
133
154
 
134
155
  private
@@ -7,14 +7,14 @@ class Admin::UsersController < Admin::ResourceController
7
7
  update.before :save_user_roles
8
8
 
9
9
  def index
10
- respond_to do |format|
10
+ respond_with(@collection) do |format|
11
11
  format.html
12
12
  format.json { render :json => json_data }
13
13
  end
14
14
  end
15
15
 
16
16
  protected
17
-
17
+
18
18
  def collection
19
19
  return @collection if @collection.present?
20
20
  unless request.xhr?
@@ -30,8 +30,8 @@ class Admin::UsersController < Admin::ResourceController
30
30
  {:search => "#{params[:q].strip}%"}).
31
31
  limit(params[:limit] || 100)
32
32
  end
33
- end
34
-
33
+ end
34
+
35
35
  def save_user_roles
36
36
  return unless params[:user]
37
37
  return unless @user.respond_to?(:roles) # since roles are technically added by the auth module
@@ -42,7 +42,7 @@ class Admin::UsersController < Admin::ResourceController
42
42
  }
43
43
  params[:user].delete(:role)
44
44
  end
45
-
45
+
46
46
  private
47
47
 
48
48
  # Allow different formats of json data to suit different ajax calls
@@ -14,18 +14,18 @@ class Admin::VariantsController < Admin::ResourceController
14
14
  flash.notice = I18n.t("notice_messages.variant_not_deleted")
15
15
  end
16
16
 
17
- respond_to do |format|
17
+ respond_with(@variant) do |format|
18
18
  format.html { redirect_to admin_product_variants_url(params[:product_id]) }
19
19
  format.js { render_js_for_destroy }
20
20
  end
21
21
  end
22
-
22
+
23
23
  def update_positions
24
24
  params[:positions].each do |id, index|
25
25
  Variant.update_all(['position=?', index], ['id=?', id])
26
26
  end
27
-
28
- respond_to do |format|
27
+
28
+ respond_with(@variant) do |format|
29
29
  format.html { redirect_to admin_product_variants_url(params[:product_id]) }
30
30
  format.js { render :text => 'Ok' }
31
31
  end
@@ -1,10 +1,11 @@
1
1
  class Admin::ZonesController < Admin::ResourceController
2
2
  before_filter :load_data, :except => [:index]
3
-
3
+
4
4
  def new
5
5
  @zone.zone_members.build
6
+ respond_with(@zone)
6
7
  end
7
-
8
+
8
9
  protected
9
10
 
10
11
  def collection
@@ -7,6 +7,8 @@ class CheckoutController < Spree::BaseController
7
7
  before_filter :load_order
8
8
  rescue_from Spree::GatewayError, :with => :rescue_from_spree_gateway_error
9
9
 
10
+ respond_to :html
11
+
10
12
  # Updates the order and advances to the next state (when possible.)
11
13
  def update
12
14
  if @order.update_attributes(object_params)
@@ -14,19 +16,18 @@ class CheckoutController < Spree::BaseController
14
16
  state_callback(:after)
15
17
  else
16
18
  flash[:error] = I18n.t(:payment_processing_failed)
17
- redirect_to checkout_state_path(@order.state) and return
19
+ respond_with(@order, :location => checkout_state_path(@order.state)) and return
18
20
  end
19
21
 
20
22
  if @order.state == "complete" || @order.completed?
21
23
  flash[:notice] = I18n.t(:order_processed_successfully)
22
24
  flash[:commerce_tracking] = "nothing special"
23
- redirect_to completion_route
25
+ respond_with(@order, :location => completion_route)
24
26
  else
25
- redirect_to checkout_state_path(@order.state)
27
+ respond_with(@order, :location => checkout_state_path(@order.state))
26
28
  end
27
-
28
29
  else
29
- render :edit
30
+ respond_with(@order) { |format| format.html { render :edit } }
30
31
  end
31
32
  end
32
33
 
@@ -5,11 +5,17 @@ class ContentController < Spree::BaseController
5
5
  rescue_from ActionView::MissingTemplate, :with => :render_404
6
6
  caches_page :show, :index, :if => Proc.new { Spree::Config[:cache_static_content] }
7
7
 
8
+ respond_to :html
9
+
8
10
  def show
9
- render :template => params[:path]
11
+ respond_with do |format|
12
+ format.html { render :template => params[:path] }
13
+ end
10
14
  end
11
15
 
12
16
  def cvv
13
- render "cvv", :layout => false
17
+ respond_with do |format|
18
+ format.html { render "cvv", :layout => false }
19
+ end
14
20
  end
15
21
  end
@@ -1,7 +1,9 @@
1
1
  class OrdersController < Spree::BaseController
2
+ respond_to :html
2
3
 
3
4
  helper :products
4
5
 
6
+
5
7
  def show
6
8
  @order = Order.find_by_number(params[:id])
7
9
  end
@@ -10,9 +12,9 @@ class OrdersController < Spree::BaseController
10
12
  @order = current_order
11
13
  if @order.update_attributes(params[:order])
12
14
  @order.line_items = @order.line_items.select {|li| li.quantity > 0 }
13
- redirect_to cart_path
15
+ respond_with(@order) { |format| format.html { redirect_to cart_path } }
14
16
  else
15
- render :edit
17
+ respond_with(@order)
16
18
  end
17
19
  end
18
20
 
@@ -45,17 +47,18 @@ class OrdersController < Spree::BaseController
45
47
  @order.add_variant(Variant.find(variant_id), quantity) if quantity > 0
46
48
  end if params[:variants]
47
49
 
48
- redirect_to cart_path
50
+ respond_with(@order) { |format| format.html { redirect_to cart_path } }
49
51
  end
50
52
 
51
53
  def empty
52
54
  if @order = current_order
53
55
  @order.line_items.destroy_all
54
56
  end
55
- redirect_to cart_path
57
+
58
+ respond_with(@order) { |format| format.html { redirect_to cart_path } }
56
59
  end
57
60
 
58
61
  def accurate_title
59
- I18n.t(:shopping_cart)
62
+ @order && @order.completed? ? "#{Order.human_name} #{@order.number}" : I18n.t(:shopping_cart)
60
63
  end
61
64
  end
@@ -3,19 +3,21 @@ class ProductsController < Spree::BaseController
3
3
  rescue_from ActiveRecord::RecordNotFound, :with => :render_404
4
4
  helper :taxons
5
5
 
6
+ respond_to :html
7
+
6
8
  def index
7
9
  @searcher = Spree::Config.searcher_class.new(params)
8
10
  @products = @searcher.retrieve_products
11
+
12
+ respond_with(@products)
9
13
  end
10
14
 
11
15
  def show
12
16
  @product = Product.find_by_permalink!(params[:id])
13
17
  return unless @product
14
-
15
- @variants = Variant.active.find_all_by_product_id(@product.id,
16
- :include => [:option_values, :images])
17
- @product_properties = ProductProperty.find_all_by_product_id(@product.id,
18
- :include => [:property])
18
+
19
+ @variants = Variant.active.includes([:option_values, :images]).where(:product_id => @product.id)
20
+ @product_properties = ProductProperty.includes(:property).where(:product_id => @product.id)
19
21
  @selected_variant = @variants.detect { |v| v.available? }
20
22
 
21
23
  referer = request.env['HTTP_REFERER']
@@ -23,6 +25,8 @@ class ProductsController < Spree::BaseController
23
25
  if referer && referer.match(HTTP_REFERER_REGEXP)
24
26
  @taxon = Taxon.find_by_permalink($1)
25
27
  end
28
+
29
+ respond_with(@product)
26
30
  end
27
31
 
28
32
  private
@@ -1,3 +1,4 @@
1
1
  class Spree::BaseController < ActionController::Base
2
2
  include SpreeBase
3
+ include SpreeRespondWith
3
4
  end
@@ -2,12 +2,16 @@ class TaxonsController < Spree::BaseController
2
2
  rescue_from ActiveRecord::RecordNotFound, :with => :render_404
3
3
  helper :products
4
4
 
5
+ respond_to :html
6
+
5
7
  def show
6
8
  @taxon = Taxon.find_by_permalink!(params[:id])
7
9
  return unless @taxon
8
-
10
+
9
11
  @searcher = Spree::Config.searcher_class.new(params.merge(:taxon => @taxon.id))
10
12
  @products = @searcher.retrieve_products
13
+
14
+ respond_with(@taxon)
11
15
  end
12
16
 
13
17
  private
@@ -2,4 +2,17 @@ module Admin::TaxonsHelper
2
2
  def taxon_path(taxon)
3
3
  taxon.ancestors.reverse.collect { |ancestor| ancestor.name }.join( " >> ")
4
4
  end
5
- end
5
+
6
+ def taxons_checkbox_tree(root, product)
7
+ return '' if root.children.blank?
8
+ content_tag 'ul' do
9
+ root.children.map do |taxon|
10
+ content_tag 'li' do
11
+ [check_box_tag("taxon_ids[]", taxon.id, product.taxons.include?(taxon), :id => "taxon_ids_#{taxon.id}"),
12
+ label_tag("taxon_ids_#{taxon.id}", taxon.name)].join('&nbsp;').html_safe +
13
+ taxons_checkbox_tree(taxon, product)
14
+ end.html_safe
15
+ end.join("\n").html_safe
16
+ end
17
+ end
18
+ end