Created
August 9, 2012 05:36
-
-
Save wesgarrison/3301337 to your computer and use it in GitHub Desktop.
Overriding Spree tax calculations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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