spree_core 1.2.0 → 1.2.2

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.
Files changed (98) hide show
  1. data/app/assets/javascripts/admin/admin.js.erb +10 -9
  2. data/app/assets/javascripts/admin/checkouts/edit.js +4 -4
  3. data/app/assets/javascripts/admin/product_autocomplete.js.erb +5 -5
  4. data/app/assets/javascripts/admin/taxon_autocomplete.js.erb +34 -0
  5. data/app/assets/javascripts/admin/taxonomy.js +11 -11
  6. data/app/assets/javascripts/store/cart.js.coffee +5 -2
  7. data/app/assets/javascripts/store/checkout.js.coffee +8 -4
  8. data/app/assets/stylesheets/admin/admin-form.css.erb +4 -0
  9. data/app/assets/stylesheets/store/screen.css.scss +1 -1
  10. data/app/controllers/spree/admin/banners_controller.rb +2 -2
  11. data/app/controllers/spree/admin/mail_methods_controller.rb +7 -0
  12. data/app/controllers/spree/admin/orders_controller.rb +3 -1
  13. data/app/controllers/spree/admin/payment_methods_controller.rb +7 -1
  14. data/app/controllers/spree/admin/products_controller.rb +11 -6
  15. data/app/controllers/spree/admin/prototypes_controller.rb +1 -1
  16. data/app/controllers/spree/admin/search_controller.rb +11 -31
  17. data/app/controllers/spree/admin/taxons_controller.rb +8 -0
  18. data/app/controllers/spree/checkout_controller.rb +7 -1
  19. data/app/controllers/spree/home_controller.rb +1 -0
  20. data/app/controllers/spree/orders_controller.rb +18 -5
  21. data/app/controllers/spree/products_controller.rb +1 -0
  22. data/app/controllers/spree/taxons_controller.rb +1 -0
  23. data/app/helpers/spree/admin/general_settings_helper.rb +1 -1
  24. data/app/helpers/spree/base_helper.rb +1 -1
  25. data/app/models/spree/ability.rb +5 -0
  26. data/app/models/spree/app_configuration.rb +1 -0
  27. data/app/models/spree/calculator/price_sack.rb +5 -3
  28. data/app/models/spree/credit_card.rb +2 -2
  29. data/app/models/spree/image.rb +2 -1
  30. data/app/models/spree/inventory_unit.rb +11 -3
  31. data/app/models/spree/line_item.rb +3 -2
  32. data/app/models/spree/order.rb +52 -9
  33. data/app/models/spree/order/checkout.rb +5 -8
  34. data/app/models/spree/payment.rb +1 -1
  35. data/app/models/spree/payment/processing.rb +21 -16
  36. data/app/models/spree/payment_method.rb +1 -1
  37. data/app/models/spree/preference.rb +1 -1
  38. data/app/models/spree/preferences/preferable_class_methods.rb +2 -0
  39. data/app/models/spree/preferences/store.rb +20 -2
  40. data/app/models/spree/product.rb +16 -0
  41. data/app/models/spree/product/scopes.rb +19 -8
  42. data/app/models/spree/return_authorization.rb +1 -0
  43. data/app/models/spree/shipment.rb +6 -4
  44. data/app/models/spree/shipping_method.rb +5 -6
  45. data/app/models/spree/tax_rate.rb +4 -2
  46. data/app/models/spree/taxon.rb +7 -0
  47. data/app/models/spree/variant.rb +26 -15
  48. data/app/views/spree/admin/banners/_gateway.html.erb +14 -0
  49. data/app/views/spree/admin/general_settings/edit.html.erb +13 -4
  50. data/app/views/spree/admin/orders/_form.html.erb +1 -1
  51. data/app/views/spree/admin/orders/customer_details/_form.html.erb +1 -1
  52. data/app/views/spree/admin/product_properties/index.html.erb +1 -1
  53. data/app/views/spree/admin/products/_form.html.erb +7 -8
  54. data/app/views/spree/admin/products/new.html.erb +1 -1
  55. data/app/views/spree/admin/return_authorizations/_form.html.erb +17 -33
  56. data/app/views/spree/admin/search/users.rabl +32 -0
  57. data/app/views/spree/admin/shared/_head.html.erb +3 -13
  58. data/app/views/spree/admin/shared/_routes.html.erb +8 -0
  59. data/app/views/spree/admin/shared/_translations.html.erb +26 -0
  60. data/app/views/spree/admin/tax_rates/_form.html.erb +8 -0
  61. data/app/views/spree/admin/tax_rates/index.html.erb +5 -1
  62. data/app/views/spree/admin/taxonomies/edit.erb +2 -2
  63. data/app/views/spree/admin/taxonomies/get_children.json.erb +1 -1
  64. data/app/views/spree/admin/taxons/search.rabl +5 -0
  65. data/app/views/spree/checkout/_confirm.html.erb +1 -0
  66. data/app/views/spree/checkout/payment/_gateway.html.erb +1 -1
  67. data/app/views/spree/orders/_adjustments.html.erb +1 -1
  68. data/app/views/spree/orders/edit.html.erb +3 -1
  69. data/app/views/spree/products/_cart_form.html.erb +3 -3
  70. data/app/views/spree/products/_thumbnails.html.erb +1 -1
  71. data/app/views/spree/shared/_head.html.erb +0 -2
  72. data/app/views/spree/shared/_order_details.html.erb +2 -2
  73. data/app/views/spree/shared/_products.html.erb +1 -1
  74. data/app/views/spree/shared/_taxonomies.html.erb +1 -1
  75. data/app/views/spree/shipment_mailer/shipped_email.text.erb +1 -1
  76. data/config/initializers/check_for_orphaned_preferences.rb +1 -1
  77. data/config/initializers/rails_5868.rb +8 -0
  78. data/config/locales/en.yml +4 -0
  79. data/config/routes.rb +13 -0
  80. data/db/default/spree/countries.yml +6 -0
  81. data/db/migrate/20120905145253_add_tax_rate_label.rb +5 -0
  82. data/db/migrate/20120905151823_add_toggle_tax_rate_display.rb +5 -0
  83. data/db/migrate/20121009142519_add_lock_version_to_variant.rb +5 -0
  84. data/db/migrate/20121017010007_remove_not_null_constraint_from_products_on_hand.rb +11 -0
  85. data/lib/generators/spree/custom_user/custom_user_generator.rb +4 -1
  86. data/lib/spree/core.rb +3 -2
  87. data/lib/spree/core/mail_settings.rb +2 -1
  88. data/lib/spree/core/permalinks.rb +1 -2
  89. data/lib/spree/core/search/base.rb +1 -0
  90. data/lib/spree/core/testing_support/authorization_helpers.rb +30 -0
  91. data/lib/spree/core/testing_support/factories/product_factory.rb +1 -1
  92. data/lib/spree/core/testing_support/flash.rb +17 -0
  93. data/lib/spree/core/testing_support/preferences.rb +26 -0
  94. data/lib/spree/core/version.rb +1 -1
  95. data/lib/spree/money.rb +4 -1
  96. metadata +69 -46
  97. data/config/initializers/workarounds_for_ruby19.rb +0 -72
  98. data/lib/spree/core/testing_support/env.rb +0 -2
@@ -3,7 +3,7 @@ module Spree
3
3
  DISPLAY = [:both, :front_end, :back_end]
4
4
  default_scope where(:deleted_at => nil)
5
5
 
6
- scope :production, where(:environment => 'production')
6
+ scope :production, lambda { where(:environment => 'production') }
7
7
 
8
8
  attr_accessible :name, :description, :environment, :display_on, :active
9
9
 
@@ -4,7 +4,7 @@ class Spree::Preference < ActiveRecord::Base
4
4
  validates :key, :presence => true
5
5
  validates :value_type, :presence => true
6
6
 
7
- scope :valid, where(Spree::Preference.arel_table[:key].not_eq(nil)).where(Spree::Preference.arel_table[:value_type].not_eq(nil))
7
+ scope :valid, lambda { where(Spree::Preference.arel_table[:key].not_eq(nil)).where(Spree::Preference.arel_table[:value_type].not_eq(nil)) }
8
8
 
9
9
  # The type conversions here should match
10
10
  # the ones in spree::preferences::preferrable#convert_preference_value
@@ -15,6 +15,8 @@ module Spree::Preferences
15
15
  else
16
16
  if get_pending_preference(name)
17
17
  get_pending_preference(name)
18
+ elsif Spree::Preference.table_exists? && preference = Spree::Preference.find_by_name(name)
19
+ preference.value
18
20
  else
19
21
  send self.class.preference_default_getter_method(name)
20
22
  end
@@ -23,11 +23,29 @@ module Spree::Preferences
23
23
  end
24
24
 
25
25
  def exist?(key)
26
- @cache.exist? key
26
+ @cache.exist?(key) ||
27
+ should_persist? && Spree::Preference.where(:key => key).exists?
27
28
  end
28
29
 
29
30
  def get(key)
30
- @cache.read(key)
31
+ # return the retrieved value, if it's in the cache
32
+ if (val = @cache.read(key)).present?
33
+ return val
34
+ end
35
+
36
+ return nil unless should_persist?
37
+
38
+ # If it's not in the cache, maybe it's in the database, but
39
+ # has been cleared from the cache
40
+
41
+ # does it exist in the database?
42
+ if preference = Spree::Preference.find_by_key(key)
43
+ # it does exist, so let's put it back into the cache
44
+ @cache.write(preference.key, preference.value)
45
+
46
+ # and return the value
47
+ preference.value
48
+ end
31
49
  end
32
50
 
33
51
  def delete(key)
@@ -44,6 +44,8 @@ module Spree
44
44
  :conditions => { :deleted_at => nil },
45
45
  :dependent => :destroy
46
46
 
47
+ has_many :variants_including_master_and_deleted, :class_name => 'Spree::Variant'
48
+
47
49
  delegate_belongs_to :master, :sku, :price, :weight, :height, :width, :depth, :is_master
48
50
  delegate_belongs_to :master, :cost_price if Variant.table_exists? && Variant.column_names.include?('cost_price')
49
51
 
@@ -97,6 +99,16 @@ module Spree
97
99
  variants.any?
98
100
  end
99
101
 
102
+ # should product be displayed on products pages and search
103
+ def on_display?
104
+ has_stock? || Spree::Config[:show_zero_stock_products]
105
+ end
106
+
107
+ # is this product actually available for purchase
108
+ def on_sale?
109
+ has_stock? || Spree::Config[:allow_backorders]
110
+ end
111
+
100
112
  # returns the number of inventory units "on_hand" for this product
101
113
  def on_hand
102
114
  has_variants? ? variants.sum(&:on_hand) : master.on_hand
@@ -179,6 +191,10 @@ module Spree
179
191
  !!deleted_at
180
192
  end
181
193
 
194
+ def available?
195
+ !(available_on.nil? || available_on.future?)
196
+ end
197
+
182
198
  # split variants list into hash which shows mapping of opt value onto matching variants
183
199
  # eg categorise_variants_from_option(color) => {"red" -> [...], "blue" -> [...]}
184
200
  def categorise_variants_from_option(opt_type)
@@ -50,8 +50,23 @@ module Spree
50
50
  # If you need products only within one taxon use
51
51
  #
52
52
  # Spree::Product.taxons_id_eq(x)
53
+ #
54
+ # If you're using count on the result of this scope, you must use the
55
+ # `:distinct` option as well:
56
+ #
57
+ # Spree::Product.in_taxon(taxon).count(:distinct => true)
58
+ #
59
+ # This is so that the count query is distinct'd:
60
+ #
61
+ # SELECT COUNT(DISTINCT "spree_products"."id") ...
62
+ #
63
+ # vs.
64
+ #
65
+ # SELECT COUNT(*) ...
53
66
  add_search_scope :in_taxon do |taxon|
54
- joins(:taxons).where(Taxon.table_name => { :id => taxon.self_and_descendants.map(&:id) })
67
+ select("DISTINCT(spree_products.id), spree_products.*").
68
+ joins(:taxons).
69
+ where(Taxon.table_name => { :id => taxon.self_and_descendants.map(&:id) })
55
70
  end
56
71
 
57
72
  # This scope selects products in all taxons AND all its descendants
@@ -63,10 +78,6 @@ module Spree
63
78
  taxons.first ? prepare_taxon_conditions(taxons) : scoped
64
79
  end
65
80
 
66
- # def self.in_cached_group(product_group)
67
- # joins(:product_groups).where('spree_product_groups_products.product_group_id' => product_group)
68
- # end
69
-
70
81
  # a scope that finds all products having property specified by name, object or id
71
82
  add_search_scope :with_property do |property|
72
83
  properties = Property.table_name
@@ -113,7 +124,7 @@ module Spree
113
124
  end
114
125
 
115
126
  conditions = "#{option_values}.name = ? AND #{option_values}.option_type_id = ?", value, option_type_id
116
- select("DISTINCT spree_products.id").joins(:variants_including_master => :option_values).where(conditions)
127
+ group("spree_products.id").joins(:variants_including_master => :option_values).where(conditions)
117
128
  end
118
129
 
119
130
  # Finds all products which have either:
@@ -188,11 +199,11 @@ module Spree
188
199
 
189
200
  add_search_scope :on_hand do
190
201
  variants_table = Variant.table_name
191
- where("#{table_name}.id in (select product_id from #{variants_table} where product_id = #{table_name}.id group by product_id having sum(count_on_hand) > 0)")
202
+ where("#{table_name}.id in (select product_id from #{variants_table} where product_id = #{table_name}.id and #{variants_table}.deleted_at IS NULL group by product_id having sum(count_on_hand) > 0)")
192
203
  end
193
204
 
194
205
  add_search_scope :taxons_name_eq do |name|
195
- select("DISTINCT spree_products.id").joins(:taxons).where(Taxon.arel_table[:name].eq(name))
206
+ group("spree_products.id").joins(:taxons).where(Taxon.arel_table[:name].eq(name))
196
207
  end
197
208
 
198
209
  if (ActiveRecord::Base.connection.adapter_name == 'PostgreSQL')
@@ -72,6 +72,7 @@ module Spree
72
72
  credit.source = self
73
73
  credit.adjustable = order
74
74
  credit.save
75
+ order.return if inventory_units.all?(&:returned?)
75
76
  end
76
77
 
77
78
  def allow_receive?
@@ -26,9 +26,10 @@ module Spree
26
26
 
27
27
  make_permalink :field => :number
28
28
 
29
- scope :shipped, where(:state => 'shipped')
30
- scope :ready, where(:state => 'ready')
31
- scope :pending, where(:state => 'pending')
29
+ scope :with_state, lambda { |s| where(:state => s) }
30
+ scope :shipped, with_state('shipped')
31
+ scope :ready, with_state('ready')
32
+ scope :pending, with_state('pending')
32
33
 
33
34
  def to_param
34
35
  number if number
@@ -114,10 +115,11 @@ module Spree
114
115
 
115
116
  # Determines the appropriate +state+ according to the following logic:
116
117
  #
117
- # pending unless +order.payment_state+ is +paid+
118
+ # pending unless order is complete and +order.payment_state+ is +paid+
118
119
  # shipped if already shipped (ie. does not change the state)
119
120
  # ready all other cases
120
121
  def determine_state(order)
122
+ return 'pending' unless order.complete?
121
123
  return 'pending' if inventory_units.any? &:backordered?
122
124
  return 'shipped' if state == 'shipped'
123
125
  order.paid? ? 'ready' : 'pending'
@@ -1,6 +1,9 @@
1
1
  module Spree
2
2
  class ShippingMethod < ActiveRecord::Base
3
3
  DISPLAY = [:both, :front_end, :back_end]
4
+
5
+ default_scope where(:deleted_at => nil)
6
+
4
7
  has_many :shipments
5
8
  validates :name, :zone, :presence => true
6
9
 
@@ -13,17 +16,13 @@ module Spree
13
16
  calculated_adjustments
14
17
 
15
18
  def available?(order, display_on = nil)
16
- displayable? && calculator.available?(order)
19
+ displayable?(display_on) && calculator.available?(order)
17
20
  end
18
21
 
19
- def displayable?
22
+ def displayable?(display_on)
20
23
  (self.display_on == display_on.to_s || self.display_on.blank?)
21
24
  end
22
25
 
23
- def calculator_available?(order)
24
- caluclator.available?(order)
25
- end
26
-
27
26
  def within_zone?(order)
28
27
  zone && zone.include?(order.ship_address)
29
28
  end
@@ -20,7 +20,7 @@ module Spree
20
20
  calculated_adjustments
21
21
  scope :by_zone, lambda { |zone| where(:zone_id => zone) }
22
22
 
23
- attr_accessible :amount, :tax_category_id, :calculator, :zone_id, :included_in_price
23
+ attr_accessible :amount, :tax_category_id, :calculator, :zone_id, :included_in_price, :name, :show_rate_in_label
24
24
 
25
25
  # Gets the array of TaxRates appropriate for the specified order
26
26
  def self.match(order)
@@ -73,7 +73,9 @@ module Spree
73
73
  private
74
74
 
75
75
  def create_label
76
- "#{tax_category.name} #{amount * 100}%"
76
+ label = ""
77
+ label << (name.present? ? name : tax_category.name) + " "
78
+ label << (show_rate_in_label? ? "#{amount * 100}%" : "")
77
79
  end
78
80
  end
79
81
  end
@@ -51,5 +51,12 @@ module Spree
51
51
  scope
52
52
  end
53
53
 
54
+ def pretty_name
55
+ ancestor_chain = self.ancestors.inject("") do |name, ancestor|
56
+ name += "#{ancestor.name} -> "
57
+ end
58
+ ancestor_chain + "#{name}"
59
+ end
60
+
54
61
  end
55
62
  end
@@ -6,7 +6,7 @@ module Spree
6
6
  :tax_category_id, :shipping_category_id, :meta_description,
7
7
  :meta_keywords, :tax_category
8
8
 
9
- attr_accessible :name, :presentation, :cost_price,
9
+ attr_accessible :name, :presentation, :cost_price, :lock_version,
10
10
  :position, :on_hand, :option_value_ids,
11
11
  :product_id, :option_values_attributes, :price,
12
12
  :weight, :height, :width, :depth, :sku
@@ -21,30 +21,21 @@ module Spree
21
21
  validates :cost_price, :numericality => { :greater_than_or_equal_to => 0, :allow_nil => true } if self.table_exists? && self.column_names.include?('cost_price')
22
22
  validates :count_on_hand, :numericality => true
23
23
 
24
+ after_save :process_backorders
24
25
  after_save :recalculate_product_on_hand, :if => :is_master?
25
26
 
26
27
  # default variant scope only lists non-deleted variants
27
- scope :active, where(:deleted_at => nil)
28
- scope :deleted, where('deleted_at IS NOT NULL')
28
+ scope :active, lambda { where(:deleted_at => nil) }
29
+ scope :deleted, lambda { where('deleted_at IS NOT NULL') }
29
30
 
30
31
  # Returns number of inventory units for this variant (new records haven't been saved to database, yet)
31
32
  def on_hand
32
33
  Spree::Config[:track_inventory_levels] ? count_on_hand : (1.0 / 0) # Infinity
33
34
  end
34
35
 
35
- # Adjusts the inventory units to match the given new level.
36
+ # set actual attribute
36
37
  def on_hand=(new_level)
37
38
  if Spree::Config[:track_inventory_levels]
38
- new_level = new_level.to_i
39
-
40
- # increase Inventory when
41
- if new_level > on_hand
42
- # fill backordered orders before creating new units
43
- backordered_units = inventory_units.with_state('backordered')
44
- backordered_units.slice(0, new_level).each(&:fill_backorder)
45
- new_level -= backordered_units.length
46
- end
47
-
48
39
  self.count_on_hand = new_level
49
40
  else
50
41
  raise 'Cannot set on_hand value when Spree::Config[:track_inventory_levels] is false'
@@ -134,9 +125,29 @@ module Spree
134
125
 
135
126
  private
136
127
 
128
+ def process_backorders
129
+ if count_changes = changes['count_on_hand']
130
+ new_level = count_changes.last
131
+
132
+ if Spree::Config[:track_inventory_levels]
133
+ new_level = new_level.to_i
134
+
135
+ # update backorders if level is positive
136
+ if new_level > 0
137
+ # fill backordered orders before creating new units
138
+ backordered_units = inventory_units.with_state('backordered')
139
+ backordered_units.slice(0, new_level).each(&:fill_backorder)
140
+ new_level -= backordered_units.length
141
+ end
142
+
143
+ self.update_attribute_without_callbacks(:count_on_hand, new_level)
144
+ end
145
+ end
146
+ end
147
+
137
148
  # strips all non-price-like characters from the price, taking into account locale settings
138
149
  def parse_price(price)
139
- price = price.to_s
150
+ return price unless price.is_a?(String)
140
151
 
141
152
  separator, delimiter = I18n.t([:'number.currency.format.separator', :'number.currency.format.delimiter'])
142
153
  non_price_characters = /[^0-9\-#{separator}]/
@@ -0,0 +1,14 @@
1
+ <% if !spree_current_user.dismissed_banner?(:gateway) &&
2
+ Spree::PaymentMethod.production.where("type != 'Spree::Gateway::Bogus'").empty? %>
3
+
4
+ <div class="banner payment_banner">
5
+ <p class="message">
6
+ <%= t(:payment_processor_choose_banner_text)%>
7
+ <%= link_to t(:payment_processor_choose_link), "http://spreecommerce.com/products/payment_processing", :target => '_blank' %>
8
+ </p>
9
+
10
+ <%= link_to t(:dismiss_banner), dismiss_admin_banner_path(:gateway),
11
+ :remote => true, :method => :post, :class => 'dismiss', :id => "dismiss-banner" %>
12
+ </div>
13
+
14
+ <% end %>
@@ -10,10 +10,19 @@
10
10
  <%= preference_field_tag(key, Spree::Config[key], :type => type) %>
11
11
  <%= label_tag(key, t(key)) + tag(:br) if type == :boolean %>
12
12
  <% end %>
13
- <p>
14
- <%= label_tag :currency, t(:currency) %>
15
- <%= select_tag :currency, currency_options %>
16
- </p>
13
+
14
+ <p>
15
+ <%= label_tag :currency, t(:currency) %>
16
+ <%= select_tag :currency, currency_options %>
17
+ </p>
18
+
19
+ <p>
20
+ <strong><%= t(:currency_symbol_position) %></strong><br>
21
+ <%= radio_button_tag :currency_symbol_position, "before" %>
22
+ <%= label_tag :currency_symbol_position_before, Spree::Money.new(10, :symbol_position => "before") %><br>
23
+ <%= radio_button_tag :currency_symbol_position, "after" %>
24
+ <%= label_tag :currency_symbol_position_after, Spree::Money.new(10, :symbol_position => "after") %>
25
+ </p>
17
26
  </fieldset>
18
27
 
19
28
  <p class="form-buttons" data-hook="buttons">
@@ -26,7 +26,7 @@
26
26
  </tr>
27
27
  </tbody>
28
28
  <tbody id="order-charges" data-hook="admin_order_form_adjustments">
29
- <% @order.adjustments.each do |adjustment| %>
29
+ <% @order.adjustments.eligible.each do |adjustment| %>
30
30
  <tr>
31
31
  <td colspan="3"><strong><%= adjustment.label %></strong></td>
32
32
  <td class="total"><span><%= adjustment.display_amount %></span></td>
@@ -43,6 +43,6 @@
43
43
  </p>
44
44
 
45
45
  <% content_for :head do %>
46
- <%= javascript_include_tag states_url, 'admin/address_states.js' %>
46
+ <%= javascript_include_tag states_path, 'admin/address_states.js' %>
47
47
  <% end %>
48
48
  </div>
@@ -39,7 +39,7 @@
39
39
  <% end %>
40
40
 
41
41
  <%= javascript_tag do -%>
42
- var properties = [<%= @properties.map{|id| "'#{id}'"}.join(', ') %>];
42
+ var properties = <%= raw(@properties.to_json) %>;
43
43
 
44
44
  $("#product_properties input.autocomplete").live("keydown", function(){
45
45
  already_auto_completed = $(this).is('ac_input');
@@ -88,7 +88,7 @@
88
88
 
89
89
  <%= f.field_container :taxons do %>
90
90
  <%= f.label :taxon_ids, t(:taxons) %><br />
91
- <%= f.select :taxon_ids, taxon_options_for(@product), {}, :class => "select2", :multiple => true %>
91
+ <%= f.hidden_field :taxon_ids, :value => @product.taxon_ids.join(',') %>
92
92
  <% end %>
93
93
 
94
94
  <%= f.field_container :option_types do %>
@@ -112,11 +112,10 @@
112
112
  <div data-hook="admin_product_form_additional_fields"></div>
113
113
  </div>
114
114
 
115
- <script>
115
+ <% unless Rails.env.test? %>
116
+ <script>
117
+ $("#product_option_type_ids").select2();
116
118
 
117
- $("#product_taxon_ids").select2({
118
- formatSelection: function(item) { return item.text.split(' -> ').slice(-1)[0] },
119
- });
120
-
121
- $("#product_option_type_ids").select2();
122
- </script>
119
+ $('.select2-container').css({width: '20em'})
120
+ </script>
121
+ <% end %>
@@ -59,7 +59,7 @@
59
59
  //<![CDATA[
60
60
  (function($){
61
61
  var base_url = "<%= admin_prototypes_url %>";
62
- var prototype_select = $('#product_prototype_id');
62
+ var prototype_select = $('#product_prototype_id');
63
63
  prototype_select.change(function() {
64
64
  var id = prototype_select.val();
65
65
  if (id.length) {
@@ -20,8 +20,8 @@
20
20
  <% elsif units.select(&:shipped?).empty? %>
21
21
  0
22
22
  <% else %>
23
- <%= text_field_tag "return_quantity[#{variant.id}]",
24
- @return_authorization.inventory_units.group_by(&:variant)[variant].try(:size) || 0, {:style => 'width:30px;'} %>
23
+ <%= number_field_tag "return_quantity[#{variant.id}]",
24
+ @return_authorization.inventory_units.group_by(&:variant)[variant].try(:size) || 0, {:style => 'width:50px;', :min => 0} %>
25
25
  <% end %>
26
26
  </td>
27
27
  </tr>
@@ -33,7 +33,7 @@
33
33
  <% if @return_authorization.received? %>
34
34
  <%= money @return_authorization.amount %>
35
35
  <% else %>
36
- <%= f.text_field :amount, {:style => 'width:80px;'} %> <%= t(:rma_value) %>: <span id="rma_value"></span>
36
+ <%= f.text_field :amount, {:style => 'width:80px;'} %> <%= t(:rma_value) %>: <span id="rma_value">0.00</span>
37
37
  <%= f.error_message_on :amount %>
38
38
  <% end %>
39
39
  <% end %>
@@ -45,35 +45,19 @@
45
45
  <% end %>
46
46
 
47
47
 
48
- <% content_for :head do %>
49
- <%= javascript_tag do -%>
50
- var variant_prices = new Array();
51
- <% @return_authorization.order.inventory_units.group_by(&:variant).each do | variant, units| %>
52
- variant_prices[<%= variant.id.to_s %>] = <%= variant.price %>;
53
- <% end %>
54
-
55
- function calculate_rma_price(object, value){
56
- var rma_amount = 0;
57
-
58
- $.each($("td.return_quantity input"), function(i, inpt){
59
- var variant_id = $(inpt).attr('id').replace("return_quantity_", "");
60
- rma_amount += variant_prices[variant_id] * $(inpt).val()
61
- });
48
+ <script>
49
+ $(document).ready(function(){
50
+ var rma_amount = 0;
51
+ $("td.return_quantity input").on('change', function() {
52
+ var rma_amount = 0;
53
+ $.each($("td.return_quantity input"), function(i, input) {
54
+ var variant_id = $(input).attr('id').replace("return_quantity_", "");
55
+ rma_amount += variant_prices[variant_id] * $(input).val()
56
+ });
62
57
 
63
- if(!isNaN(rma_amount)){
64
- $("span#rma_value").html(rma_amount.toFixed(2));
65
- }
58
+ if(!isNaN(rma_amount)){
59
+ $("span#rma_value").html(rma_amount.toFixed(2));
66
60
  }
67
-
68
- $(document).ready(function(){
69
- $.each($("td.return_quantity input"), function(i, inpt){
70
- $(inpt).delayedObserver(function() {
71
- calculate_rma_price();
72
- }, 0.5);
73
- });
74
-
75
- calculate_rma_price();
76
- });
77
- <% end -%>
78
- <% end %>
79
- </div>
61
+ })
62
+ });
63
+ </script>