BPE: Set defaults for price and on_hand to prevent 'I'm a teapot' error (418) on update

This commit is contained in:
Rob H
2014-03-27 15:38:44 +11:00
parent 2b035459fd
commit dae2d9db9e
2 changed files with 6 additions and 4 deletions

View File

@@ -1,8 +1,9 @@
object @product
attributes :id, :name, :price, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand
attributes :id, :name, :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( :on_hand ) { |p| p.on_hand.nil? ? 0 : p.on_hand.to_f.finite? ? p.on_hand : "On demand" }
node( :price ) { |p| p.price.nil? ? '0.0' : p.price }
node( :available_on ) { |p| p.available_on.blank? ? "" : p.available_on.strftime("%F %T") }
node( :permalink_live ) { |p| p.permalink }

View File

@@ -1,6 +1,7 @@
object @variant
attributes :id, :options_text, :price, :unit_value, :unit_description, :on_demand
attributes :id, :options_text, :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" }
node( :on_hand ) { |v| v.on_hand.nil? ? 0 : v.on_hand.to_f.finite? ? v.on_hand : "On demand" }
node( :price ) { |v| v.price.nil? ? '0.0' : v.price }