Improve admin variants controller create action, it doesn't try to set on_hand and on_demand if there are previous errors in the variant

This commit is contained in:
luisramos0
2019-03-22 23:23:10 +00:00
parent 78ea16c684
commit a8c0eef3d3

View File

@@ -6,9 +6,13 @@ Spree::Admin::VariantsController.class_eval do
def create
on_demand = params[:variant].delete(:on_demand)
on_hand = params[:variant].delete(:on_hand)
super
@object.on_demand = on_demand if @object.present?
@object.on_hand = on_hand.to_i if @object.present?
if @object.present? && @object.valid?
@object.on_demand = on_demand if on_demand.present?
@object.on_hand = on_hand.to_i if on_hand.present?
end
end
def search