Merge branch 'master' of github.com:eaterprises/openfoodweb

This commit is contained in:
alexs
2013-08-13 11:40:54 +10:00
36 changed files with 185 additions and 346 deletions

View File

@@ -28,11 +28,14 @@ module Admin
product_distribution = ProductDistribution.where(:enterprise_fee_id => @object).first
if product_distribution
p = product_distribution.product
flash[:error] = "That enterprise fee cannot be deleted as it is referenced by a product distribution: #{p.id} - #{p.name}."
error = "That enterprise fee cannot be deleted as it is referenced by a product distribution: #{p.id} - #{p.name}."
respond_with(@object) do |format|
format.html { redirect_to collection_url }
format.js { render text: flash[:error], status: 403 }
format.html do
flash[:error] = error
redirect_to collection_url
end
format.js { render text: error, status: 403 }
end
end
end

View File

@@ -3,19 +3,18 @@ module Spree
ShippingMethodsController.class_eval do
before_filter :do_not_destroy_referenced_shipping_methods, :only => :destroy
# 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?
def do_not_destroy_referenced_shipping_methods
order = Order.where(:shipping_method_id => @object).first
if order
flash[:error] = "That shipping method cannot be deleted as it is referenced by an order: #{order.number}."
redirect_to collection_url and return
end
product_distribution = ProductDistribution.where(:shipping_method_id => @object).first
if product_distribution
p = product_distribution.product
flash[:error] = "That shipping method cannot be deleted as it is referenced by a product distribution: #{p.id} - #{p.name}."
redirect_to collection_url and return
end
end
end
end