mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
DRY shipment updating
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user