Remove distributor association from orders and from the checkout process

This commit is contained in:
Rohan Mitchell
2012-06-18 17:01:08 +10:00
parent d704f3aa68
commit 82ca7112c2
6 changed files with 32 additions and 21 deletions

View File

@@ -1,7 +1,6 @@
module Spree
class Distributor < ActiveRecord::Base
self.table_name = 'distributors'
has_many :orders
belongs_to :country
belongs_to :state

View File

@@ -1,22 +1,18 @@
Spree::Order.class_eval do
attr_accessible :distributor_id
belongs_to :distributor
before_validation :shipping_address_from_distributor
# before_validation :shipping_address_from_distributor
private
def shipping_address_from_distributor
if distributor
ship_address.firstname = bill_address.firstname
ship_address.lastname = bill_address.lastname
ship_address.phone = bill_address.phone
# def shipping_address_from_distributor
# if distributor
# ship_address.firstname = bill_address.firstname
# ship_address.lastname = bill_address.lastname
# ship_address.phone = bill_address.phone
ship_address.address1 = distributor.pickup_address
ship_address.city = distributor.city
ship_address.zipcode = distributor.post_code
ship_address.state = distributor.state
ship_address.country_id = distributor.country_id
end
end
# ship_address.address1 = distributor.pickup_address
# ship_address.city = distributor.city
# ship_address.zipcode = distributor.post_code
# ship_address.state = distributor.state
# ship_address.country_id = distributor.country_id
# end
# end
end

View File

@@ -0,0 +1,12 @@
class MoveDistributorFromOrderToProduct < ActiveRecord::Migration
def change
remove_column :spree_orders, :distributor_id
add_column :spree_products, :distributor_id, :integer
Spree::Order.reset_column_information
Spree::Product.reset_column_information
# Associate all products with the first distributor so they'll be valid
distributor = Spree::Distributor.first
Spree::Product.update_all("distributor_id = #{distributor.id}") if distributor
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120520062061) do
ActiveRecord::Schema.define(:version => 20120618061537) do
create_table "distributors", :force => true do |t|
t.string "name"
@@ -248,7 +248,6 @@ ActiveRecord::Schema.define(:version => 20120520062061) do
t.string "payment_state"
t.string "email"
t.text "special_instructions"
t.integer "distributor_id"
end
add_index "spree_orders", ["number"], :name => "index_orders_on_number"
@@ -354,6 +353,7 @@ ActiveRecord::Schema.define(:version => 20120520062061) do
t.datetime "updated_at"
t.integer "count_on_hand", :default => 0, :null => false
t.integer "supplier_id"
t.integer "distributor_id"
end
add_index "spree_products", ["available_on"], :name => "index_products_on_available_on"

View File

@@ -23,7 +23,7 @@ feature %q{
end
context "Given I am buying a product", :js => true do
scenario "I should be able choose a distributor to pick up from" do
scenario "I should be able choose a distributor to pick up from", :skip => true do
login_to_consumer_section
click_link 'Fuji apples'

View File

@@ -37,6 +37,10 @@ RSpec.configure do |config|
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# ## Filters
#
config.filter_run_excluding :skip => true
config.before(:suite) do
DatabaseCleaner.strategy = :truncation, { :except => ['spree_countries', 'spree_states'] }
end