Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spree::Zone.for_address is not return actual tax rates #2195

Closed
ghost opened this issue Aug 30, 2017 · 2 comments
Closed

Spree::Zone.for_address is not return actual tax rates #2195

ghost opened this issue Aug 30, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 30, 2017

Hi, I am facing some interesting error while I am removing all deprecation method of solidus.

According to your documentation, I have to use Spree::Order#tax_address instead of tax_zone method.
I used it as like:

order = Spree::Order.first
order.tax_address

But it does not match result with order.tax_zone.
Then I was trying changing tax_zone method in my order_decorator.rb as like:

def get_tax_zone
    Spree::Zone.for_address(tax_address) || Spree::Zone.default_tax
  end

Since Spree::Zone.match is also deprecated method

But it is failed to return tax_rates! My query in rails console:

order = Spree::Order.first
order.get_tax_zone.tax_rates

It returns an error as like

NoMethodError: undefined method `tax_rates' for #<Spree::Zone::ActiveRecord_Relation:0x007ffc1d98a258>
from /Users/hta-wtag/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/activerecord-5.0.5/lib/active_record/relation/delegation.rb:124:in `method_missing'

But when I use Spree::Zone.match instead of Spree::Zone.for_address, it returns actual tax_rates of my order.

So, My Question is Why happen this ?

System configuration

Solidus Version: 2.2.1

Extensions in use:

gem 'solidus'
gem 'solidus_auth_devise'
@jhawthorn
Copy link
Contributor

I think the confusion here is because Spree::Zone.for_address returns a set of matching zones, unlike match which only ever returned a single zone (which is incorrect for a lot of cases). There's no exact direct replacement of match because it's behaviour is wrong.

These changes were made as part of the major tax refactor which went into Solidus 1.3 #989

@mamhoff
Copy link
Contributor

mamhoff commented Sep 6, 2017

To get all tax rates that apply to an order, run the following code:

Spree::TaxRate.for_address(order.tax_address)

You can just bypass the zones as an implementation detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants