diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index b1eb094558..d597e5ae51 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -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