Skip to content

Instantly share code, notes, and snippets.

@wesgarrison
Created August 9, 2012 05:36
Show Gist options
  • Select an option

  • Save wesgarrison/3301337 to your computer and use it in GitHub Desktop.

Select an option

Save wesgarrison/3301337 to your computer and use it in GitHub Desktop.
Overriding Spree tax calculations
# See http://guides.spreecommerce.com/logic_customization.html#extending-classes
# on where/how to use these
Spree::Order.class_eval do
def shipping_tax_zone
zone_address = ship_address
Spree::Zone.match(zone_address) || Spree::Zone.default_tax
end
def billing_tax_zone
zone_address = bill_address
Spree::Zone.match(zone_address) || Spree::Zone.default_tax
end
end
Spree::TaxRate.class_eval do
# Gets the array of TaxRates appropriate for the specified order
def self.match(order)
return [] unless order.tax_zone
all.select do |rate|
rate.zone == order.tax_zone || rate.zone.contains?(order.shipping_tax_zone) || rate.zone.contains?(order.billing_tax_zone) || rate.zone.default_tax
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment