From 23b5e73c97c0372c8071dcc20f28d12084d3f49e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 24 Oct 2022 16:47:27 +0200 Subject: [PATCH] Weight is computed with `unit_value` and product `variant_unit_scale` --- app/models/spree/line_item.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index 512f381f36..3f7f8e73e4 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -126,7 +126,7 @@ module Spree def copy_dimensions return unless variant - self.weight ||= variant.weight + self.weight ||= computed_weight_from_variant self.height ||= variant.height self.width ||= variant.width self.depth ||= variant.depth @@ -236,6 +236,14 @@ module Spree private + def computed_weight_from_variant + if variant.product.variant_unit == "weight" + variant.unit_value / variant.product.variant_unit_scale + else + variant.weight + end + end + def update_inventory return unless changed?