Add seperate address fields - don't become too attached to spree.

This commit is contained in:
Andrew Spinks
2012-04-29 17:31:47 +10:00
parent e4fd20b807
commit c9effe5926
7 changed files with 62 additions and 6 deletions

View File

@@ -1,9 +1,13 @@
module Spree
module Admin
class SuppliersController < ResourceController
# before_filter :load_data, :except => [:index]
before_filter :load_data, :except => [:index]
private
def load_data
@countries = Country.order(:name)
end
def collection
super.order(:name)
end

View File

@@ -1,9 +1,16 @@
module Spree
class Supplier < ActiveRecord::Base
set_table_name 'suppliers'
belongs_to :address
has_many :products
belongs_to :country
belongs_to :state
# validates :name, :pickup_address, :country_id, :state_id, :city, :post_code, :presence => true
after_initialize :initialize_country
def initialize_country
self.country = Spree::Country.find_by_id(Spree::Config[:default_country_id])
end
end
end

View File

@@ -14,14 +14,14 @@
</td>
</tr>
<tr>
<tr>
<th>Contact person</th>
<td>
<%= @distributor.contact %>
</td>
</tr>
<tr>
<tr>
<th>Phone number</th>
<td>
<%= @distributor.phone %>

View File

@@ -5,6 +5,21 @@
%tr{'data-hook' => "description"}
%td Description:
%td= f.text_field :description
%tr{'data-hook' => "address"}
%td Address:
%td= f.text_field :address
%tr{'data-hook' => "city"}
%td City:
%td= f.text_field :city
%tr{'data-hook' => "post_code"}
%td Post Code:
%td= f.text_field :postcode
%tr{'data-hook' => "country"}
%td Country:
%td= f.collection_select(:country_id, @countries, :id, :name, :include_blank => true)
%tr{'data-hook' => "state"}
%td State:
%td= f.collection_select(:state_id, @supplier.country.states, :id, :name, :include_blank => true)
%tr{'data-hook' => "email"}
%td Email:
%td= f.text_field :email

View File

@@ -6,6 +6,21 @@
%tr
%th Description
%td= @supplier.description
%tr
%th Address
%td= @supplier.address
%tr
%th City:
%td= @supplier.city
%tr
%th Post Code:
%td= @supplier.postcode
%tr
%th Country:
%td= @supplier.country.name if @supplier.country
%tr
%th State:
%td= @supplier.state.name if @supplier.state
%tr
%th Email
%td= @supplier.email

View File

@@ -0,0 +1,12 @@
class ReplaceSpreeAddressFromSupplier < ActiveRecord::Migration
def change
remove_column :suppliers, :address_id
remove_column :suppliers, :url
add_column :suppliers, :address, :string
add_column :suppliers, :city, :string
add_column :suppliers, :postcode, :string
add_column :suppliers, :state_id, :integer
add_column :suppliers, :country_id, :integer
end
end

View File

@@ -4,12 +4,15 @@ describe Spree::Supplier do
describe "associations" do
it { should have_many(:products) }
it { should belong_to(:address) }
end
it "should have an address"
it "should add an address on save"
it "should default country to system country" do
supplier = Spree::Supplier.new
supplier.country.should == Spree::Country.find_by_id(Spree::Config[:default_country_id])
end
describe 'validations' do
# it{ should validate_presence_of(:comment) }