validate price numericality on product and variants

This commit is contained in:
Mohamed ABDELLANI
2023-11-27 15:44:42 +01:00
parent d4cebfdb4f
commit a0c2facca4
2 changed files with 2 additions and 0 deletions

View File

@@ -67,6 +67,7 @@ module Spree
validates :variant_unit_name,
presence: { if: ->(p) { p.variant_unit == 'items' } }
validate :validate_image
validates :price, numericality: { greater_than_or_equal_to: 0, if: ->{ new_record? } }
accepts_nested_attributes_for :variants, allow_destroy: true
accepts_nested_attributes_for :image

View File

@@ -72,6 +72,7 @@ module Spree
}
validates :unit_value, numericality: { greater_than: 0 }
validates :price, numericality: { greater_than_or_equal_to: 0 }
validates :unit_description, presence: true, if: ->(variant) {
variant.product&.variant_unit.present? && variant.unit_value.nil?