From f8657aaf41da5ea7c5d97d8061be580cc0529706 Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Wed, 17 Aug 2022 08:13:38 +0530 Subject: [PATCH] Copy dimensions from variants to line items before validation --- app/models/spree/line_item.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) 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