DRY shipment updating

This commit is contained in:
Matt-Yorkley
2021-05-10 22:25:03 +01:00
parent 8405a7672d
commit 34eaf6f0f2

View File

@@ -13,7 +13,7 @@ module Spree
def add(variant, quantity = 1, shipment = nil)
line_item = order.find_line_item_by_variant(variant)
add_to_line_item(line_item, variant, quantity, shipment)
shipment.present? ? shipment.update_amounts : order.ensure_updated_shipments
update_shipment(shipment)
update_order
end
@@ -27,7 +27,7 @@ module Spree
end
remove_from_line_item(line_item, variant, quantity, shipment)
shipment.present? ? shipment.update_amounts : order.ensure_updated_shipments
update_shipment(shipment)
update_order
end
@@ -44,6 +44,10 @@ module Spree
private
def update_shipment(shipment)
shipment.present? ? shipment.update_amounts : order.ensure_updated_shipments
end
def add_to_line_item(line_item, variant, quantity, shipment = nil)
if line_item
line_item.target_shipment = shipment