mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Remove shipping method field from product distributions
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class ProductDistribution < ActiveRecord::Base
|
||||
belongs_to :product, :class_name => 'Spree::Product'
|
||||
belongs_to :distributor, :class_name => 'Enterprise'
|
||||
belongs_to :shipping_method, :class_name => 'Spree::ShippingMethod'
|
||||
belongs_to :enterprise_fee
|
||||
|
||||
validates_presence_of :product_id, :on => :update
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class RemoveShippingMethodFromProductDistribution < ActiveRecord::Migration
|
||||
def up
|
||||
remove_column :product_distributions, :shipping_method_id
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :product_distributions, :shipping_method_id, :integer
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130809075103) do
|
||||
ActiveRecord::Schema.define(:version => 20130812233634) do
|
||||
|
||||
create_table "adjustment_metadata", :force => true do |t|
|
||||
t.integer "adjustment_id"
|
||||
@@ -229,7 +229,6 @@ ActiveRecord::Schema.define(:version => 20130809075103) do
|
||||
create_table "product_distributions", :force => true do |t|
|
||||
t.integer "product_id"
|
||||
t.integer "distributor_id"
|
||||
t.integer "shipping_method_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "enterprise_fee_id"
|
||||
|
||||
@@ -13,8 +13,7 @@ module OpenFoodWeb
|
||||
@variant1 = create(:variant)
|
||||
@variant1.product.supplier = @supplier1
|
||||
@variant1.product.save!
|
||||
shipping_method = create(:shipping_method)
|
||||
product_distribution = create(:product_distribution, :product => @variant1.product, :distributor => distributor, :shipping_method => create(:shipping_method))
|
||||
product_distribution = create(:product_distribution, :product => @variant1.product, :distributor => distributor)
|
||||
shipping_instructions = "pick up on thursday please!"
|
||||
|
||||
order1 = create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions)
|
||||
@@ -29,7 +28,7 @@ module OpenFoodWeb
|
||||
@variant2 = create(:variant)
|
||||
@variant2.product.supplier = @supplier1
|
||||
@variant2.product.save!
|
||||
product_distribution = create(:product_distribution, :product => @variant2.product, :distributor => distributor, :shipping_method => create(:shipping_method))
|
||||
product_distribution = create(:product_distribution, :product => @variant2.product, :distributor => distributor)
|
||||
|
||||
line_item22 = create(:line_item, :variant => @variant2, :order => order2)
|
||||
order2.line_items << line_item22
|
||||
@@ -39,7 +38,7 @@ module OpenFoodWeb
|
||||
@variant3 = create(:variant, :weight => nil)
|
||||
@variant3.product.supplier = @supplier2
|
||||
@variant3.product.save!
|
||||
product_distribution = create(:product_distribution, :product => @variant3.product, :distributor => distributor, :shipping_method => create(:shipping_method))
|
||||
product_distribution = create(:product_distribution, :product => @variant3.product, :distributor => distributor)
|
||||
|
||||
order3 = create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions)
|
||||
line_item31 = create(:line_item, :variant => @variant3, :order => order3)
|
||||
|
||||
@@ -11,7 +11,7 @@ module OpenFoodWeb
|
||||
@distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
|
||||
@distributor = create(:distributor_enterprise, :address => @distributor_address)
|
||||
product = create(:product)
|
||||
product_distribution = create(:product_distribution, :product => product, :distributor => @distributor, :shipping_method => create(:shipping_method))
|
||||
product_distribution = create(:product_distribution, :product => product, :distributor => @distributor)
|
||||
@shipping_instructions = "pick up on thursday please!"
|
||||
@order = create(:order, :distributor => @distributor, :bill_address => @bill_address, :special_instructions => @shipping_instructions)
|
||||
@payment_method = create(:payment_method)
|
||||
|
||||
Reference in New Issue
Block a user