mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-09 23:06:06 +00:00
Copy dimensions from variants to line items before validation
This commit is contained in:
committed by
Jean-Baptiste Bellet
parent
f38661cdf1
commit
f8657aaf41
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user