mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-25 01:23:23 +00:00
Adapt ShippingMethodsController to keep disallowing delete of shipping_methods associated with orders. Added controller tests to verify behaviour
This commit is contained in:
@@ -17,14 +17,10 @@ module Spree
|
||||
collection
|
||||
end
|
||||
|
||||
# This method was originally written because ProductDistributions referenced shipping
|
||||
# methods, and deleting a referenced shipping method would break all the reports that
|
||||
# queried it.
|
||||
# This has changed, and now all we're protecting is Orders, which is a spree resource.
|
||||
# Do we really need to protect it ourselves? Does spree do this, or provide some means
|
||||
# of preserving the shipping method information for past orders?
|
||||
# Spree allows soft deletes of shipping_methods but our reports are not adapted to that.
|
||||
# So, this method prevents the deletion (even soft) of shipping_methods that are referenced in orders.
|
||||
def do_not_destroy_referenced_shipping_methods
|
||||
order = Order.where(:shipping_method_id => @object).first
|
||||
order = Order.joins(shipments: :shipping_rates).where( spree_shipping_rates: { :shipping_method_id => @object } ).first
|
||||
if order
|
||||
flash[:error] = I18n.t(:shipping_method_destroy_error, number: order.number)
|
||||
redirect_to collection_url and return
|
||||
|
||||
Reference in New Issue
Block a user