Fix invalid JSON for on_demand products/variants with infinite on_hand

This commit is contained in:
Rohan Mitchell
2014-01-17 14:53:03 +11:00
parent 5e0515e6c5
commit ea028ddd01
2 changed files with 8 additions and 3 deletions

View File

@@ -1,5 +1,8 @@
object @product
attributes :id, :name, :price, :on_hand, :variant_unit, :variant_unit_scale, :variant_unit_name
attributes :id, :name, :price, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand
# Infinity is not a valid JSON object, but Rails encodes it anyway
node( :on_hand ) { |p| p.on_hand.to_f.finite? ? p.on_hand : "On demand" }
node( :available_on ) { |p| p.available_on.blank? ? "" : p.available_on.strftime("%F %T") }
node( :permalink_live ) { |p| p.permalink }
@@ -9,4 +12,3 @@ end
node( :variants ) do |p|
partial 'spree/api/variants/bulk_index', :object => p.variants.order('id ASC')
end

View File

@@ -1,3 +1,6 @@
object @variant
attributes :id, :options_text, :price, :unit_value, :unit_description, :on_hand
attributes :id, :options_text, :price, :unit_value, :unit_description, :on_demand
# Infinity is not a valid JSON object, but Rails encodes it anyway
node( :on_hand ) { |p| p.on_hand.to_f.finite? ? p.on_hand : "On demand" }