mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
Fix line item destroy by forcing quantity to zero and update_inventory before_destroy so that the variant is restocked
This commit is contained in:
@@ -17,6 +17,7 @@ Spree::LineItem.class_eval do
|
||||
|
||||
before_save :calculate_final_weight_volume, if: :quantity_changed?, unless: :final_weight_volume_changed?
|
||||
after_save :update_units
|
||||
before_destroy :make_quantity_zero, :update_inventory
|
||||
|
||||
delegate :unit_description, to: :variant
|
||||
|
||||
@@ -134,6 +135,12 @@ Spree::LineItem.class_eval do
|
||||
end
|
||||
alias_method_chain :update_inventory, :scoping
|
||||
|
||||
# This is necessary before destroying the line item
|
||||
# so that update_inventory will restore stock to the variant
|
||||
def make_quantity_zero
|
||||
self.quantity = 0
|
||||
end
|
||||
|
||||
def calculate_final_weight_volume
|
||||
if final_weight_volume.present? && quantity_was > 0
|
||||
self.final_weight_volume = final_weight_volume * quantity / quantity_was
|
||||
|
||||
Reference in New Issue
Block a user