From 117085aeba216d2d756eef695a8a876a22383c9f Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 21 Sep 2023 09:48:45 +1000 Subject: [PATCH] Transform weight before validation I guess validates_length_from_database also validates numbers. That's not a bad thing. So now it's being validated, we should validate the transformed value that will be saved to the database. --- app/models/spree/variant.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 039c1ebeca..9768f00ced 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -81,8 +81,8 @@ module Spree before_validation :ensure_shipping_category before_validation :ensure_unit_value before_validation :update_weight_from_unit_value, if: ->(v) { v.product.present? } + before_validation :convert_variant_weight_to_decimal - before_save :convert_variant_weight_to_decimal before_save :assign_units, if: ->(variant) { variant.new_record? || variant.changed_attributes.keys.intersection(NAME_FIELDS).any? }