Skip to content

Commit

Permalink
Merge pull request #108 from 3drobotics/2-0-stable
Browse files Browse the repository at this point in the history
use package stock_location rather than global origin for rates
  • Loading branch information
rterbush committed Aug 8, 2013
2 parents f1d2d60 + fead0b2 commit 401e720
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/models/spree/calculator/shipping/active_shipping/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ def self.service_name

def compute(package)
order = package.order
stock_location = package.stock_location

origin= Location.new(:country => stock_location.country.iso,
:city => stock_location.city,
:state => stock_location.state_name || stock_location.state.name,
:zip => stock_location.zipcode)

origin= Location.new(:country => Spree::ActiveShipping::Config[:origin_country],
:city => Spree::ActiveShipping::Config[:origin_city],
:state => Spree::ActiveShipping::Config[:origin_state],
:zip => Spree::ActiveShipping::Config[:origin_zip])
addr = order.ship_address

destination = Location.new(:country => addr.country.iso,
Expand Down
10 changes: 10 additions & 0 deletions app/models/spree/stock_location_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Spree::StockLocation.class_eval do
validates_presence_of :address1, :city, :zipcode, :country_id
validate :state_id_or_state_name_is_present

def state_id_or_state_name_is_present
if state_id.nil? && state_name.nil?
errors.add(:state_name, "can't be blank")
end
end
end

0 comments on commit 401e720

Please sign in to comment.