Copy dimensions from variants to line items before validation

This commit is contained in:
Nihal Mohammed
2022-08-17 08:13:38 +05:30
committed by Jean-Baptiste Bellet
parent f38661cdf1
commit f8657aaf41

View File

@@ -28,6 +28,7 @@ module Spree
before_validation :adjust_quantity
before_validation :copy_price
before_validation :copy_tax_category
before_validation :copy_dimensions
validates :variant, presence: true
validates :quantity, numericality: {
@@ -122,6 +123,15 @@ module Spree
self.tax_category = variant.product.tax_category
end
def copy_dimensions
return unless variant
self.weight = variant.weight if weight.nil?
self.height = variant.height if height.nil?
self.width = variant.width if width.nil?
self.depth = variant.depth if depth.nil?
end
def amount
price * quantity
end