November Happy Hour will be moved to Thursday December 5th.

[11.8.5] Getting the tax value for a product by code?

Vote:
 

Hi,

Is there an abstraction API somewhere for getting the tax value a product, without having to add said product to a cart, configuring shipping address, and then use ITaxCalculator, and then deleting the cart again? Or should I roll my own?

I will need to roll my own, I just wondered if there is an interface or base class I should override somewhere to implement it "The EPiServer Way"...

/Paddy

#198510
Oct 30, 2018 9:58
Vote:
 

No there is no builtin functionality for that. That's interesting - if you have flat tax rate across the market then yes you should not have to care about the shipping address. 

A faster way to implement ILineItem (most importantly, to set the TaxCategoryId property), and IOrderAddress, then you can use ITaxCalculator directly without having to create a cart and then delete it. 

I will get back later if I have time 

#198514
Oct 30, 2018 10:59
Vote:
 

By "getting the tax value", do you mean the values that are configured in Commerce Manager?

For example this one:

In that case you can do something like this:

    var contentLink = _referenceConverter.GetContentLink(lineItem.Code);
    var entryContent = _contentLoader.Get<EntryContentBase>(contentLink);
    var taxCategoryId = (entryContent as IPricing)?.TaxCategoryId;


    if (taxCategoryId.HasValue)
    {
        var taxDto = TaxManager.GetTax(taxCategoryId.Value);

        var percentage = taxDto.TaxValue.FirstOrDefault().Percentage;
    }

In this case I'm getting the only one that is configured in the example above, but you can input whatever you need in the FirstOrDefault argument.

If you need to actually calculate which tax rate is applicable given various parameters (like ITaxCalculator does), then I think Quan already answered. :D

#198518
Edited, Oct 30, 2018 12:20
Vote:
 

Thanks, guys!

I decided to skip most of my problems by upgrading my upgrade project to Commerce 12 :)

Thanks for your input!!

#198566
Oct 31, 2018 10:46
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.