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:
luisramos0
2018-12-22 23:27:27 +00:00
parent 1007addddb
commit 26b5250f2c

View File

@@ -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