diff --git a/app/controllers/spree/admin/suppliers_controller.rb b/app/controllers/spree/admin/suppliers_controller.rb index 6f80b2ffeb..61debf2b04 100644 --- a/app/controllers/spree/admin/suppliers_controller.rb +++ b/app/controllers/spree/admin/suppliers_controller.rb @@ -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 diff --git a/app/models/spree/supplier.rb b/app/models/spree/supplier.rb index 2710cfd4e6..1ef9e00dff 100644 --- a/app/models/spree/supplier.rb +++ b/app/models/spree/supplier.rb @@ -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 diff --git a/app/views/spree/admin/distributors/show.html.erb b/app/views/spree/admin/distributors/show.html.erb index c6e6413aa1..aef51a026c 100644 --- a/app/views/spree/admin/distributors/show.html.erb +++ b/app/views/spree/admin/distributors/show.html.erb @@ -14,14 +14,14 @@ - + Contact person <%= @distributor.contact %> - + Phone number <%= @distributor.phone %> diff --git a/app/views/spree/admin/suppliers/_form.html.haml b/app/views/spree/admin/suppliers/_form.html.haml index 79880a9b93..982ec653e1 100644 --- a/app/views/spree/admin/suppliers/_form.html.haml +++ b/app/views/spree/admin/suppliers/_form.html.haml @@ -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 diff --git a/app/views/spree/admin/suppliers/show.html.haml b/app/views/spree/admin/suppliers/show.html.haml index 795b0ed261..1f741568f5 100644 --- a/app/views/spree/admin/suppliers/show.html.haml +++ b/app/views/spree/admin/suppliers/show.html.haml @@ -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 diff --git a/db/migrate/20120429071654_replace_spree_address_from_supplier.rb b/db/migrate/20120429071654_replace_spree_address_from_supplier.rb new file mode 100644 index 0000000000..e910b373c6 --- /dev/null +++ b/db/migrate/20120429071654_replace_spree_address_from_supplier.rb @@ -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 diff --git a/spec/models/suppliers_spec.rb b/spec/models/suppliers_spec.rb index 36b06aef61..6b8ab9617f 100644 --- a/spec/models/suppliers_spec.rb +++ b/spec/models/suppliers_spec.rb @@ -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) }