From 48c6f4d7cc8c5c28128bd7702a5cd9984111ee5f Mon Sep 17 00:00:00 2001 From: Andrew Spinks Date: Sun, 22 Apr 2012 12:10:35 +1000 Subject: [PATCH] default states to current zone. --- app/models/spree/distributor.rb | 9 ++++++++- app/models/spree/order_decorator.rb | 1 + app/overrides/replace_delivery_addres.rb | 8 ++++---- app/views/spree/admin/distributors/_form.html.erb | 4 ++++ app/views/spree/admin/distributors/show.html | 5 +++++ db/migrate/20120409004831_add_state_to_distributor.rb | 5 +++++ 6 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20120409004831_add_state_to_distributor.rb diff --git a/app/models/spree/distributor.rb b/app/models/spree/distributor.rb index ae309b250b..7db9684a58 100644 --- a/app/models/spree/distributor.rb +++ b/app/models/spree/distributor.rb @@ -3,7 +3,14 @@ module Spree set_table_name 'distributors' has_many :orders belongs_to :country + belongs_to :state - validates :name, :pickup_address, :country_id, :city, :post_code, :presence => true + 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/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 95f41c8234..4a38447903 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -15,6 +15,7 @@ Spree::Order.class_eval do 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 diff --git a/app/overrides/replace_delivery_addres.rb b/app/overrides/replace_delivery_addres.rb index 0798db7076..362e217bc0 100644 --- a/app/overrides/replace_delivery_addres.rb +++ b/app/overrides/replace_delivery_addres.rb @@ -1,5 +1,5 @@ -# Deface::Override.new(:virtual_path => "spree/checkout/_address", -# :replace => "[data-hook='shipping_fieldset_wrapper']", -# :partial => "spree/checkout/distributor", -# :name => "drop_off_point") +Deface::Override.new(:virtual_path => "spree/checkout/_address", + :replace => "[data-hook='shipping_fieldset_wrapper']", + :partial => "spree/checkout/distributor", + :name => "drop_off_point") diff --git a/app/views/spree/admin/distributors/_form.html.erb b/app/views/spree/admin/distributors/_form.html.erb index 62cd441cc9..d7db0cbbdb 100644 --- a/app/views/spree/admin/distributors/_form.html.erb +++ b/app/views/spree/admin/distributors/_form.html.erb @@ -40,6 +40,10 @@ Country: <%= f.collection_select(:country_id, @countries, :id, :name, :include_blank => true) %> + + State: + <%= f.collection_select(:state_id, @distributor.country.states, :id, :name, :include_blank => true) %> + Pickup times: diff --git a/app/views/spree/admin/distributors/show.html b/app/views/spree/admin/distributors/show.html index 1440df268a..c6e6413aa1 100644 --- a/app/views/spree/admin/distributors/show.html +++ b/app/views/spree/admin/distributors/show.html @@ -55,6 +55,11 @@ <%= @distributor.country.name if @distributor.country %> + Pickup state + + <%= @distributor.state.name if @distributor.state %> + + Pickup times diff --git a/db/migrate/20120409004831_add_state_to_distributor.rb b/db/migrate/20120409004831_add_state_to_distributor.rb new file mode 100644 index 0000000000..5480039a1a --- /dev/null +++ b/db/migrate/20120409004831_add_state_to_distributor.rb @@ -0,0 +1,5 @@ +class AddStateToDistributor < ActiveRecord::Migration + def change + add_column :distributors, :state_id, :integer + end +end