What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello, following the spryker code for tax rate calculation there is a function which will be called

UPWG9AYH2
UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet

Hello,
following the spryker code for tax rate calculation there is a function which will be called when adding an item via glue addItemToCart endpoint

protected function recalculateWithItemsAndShippingAddress(ArrayObject $itemTransfers, ?AddressTransfer $shippingAddressTransfer): ArrayObject
{
    $countryIso2Code = $this->getShippingCountryIso2Code($shippingAddressTransfer);
    $allIdProductAbstracts = $this->getAllIdAbstractProducts($itemTransfers);

    $taxRates = $this->findTaxRatesByAllIdProductAbstractsAndCountryIso2Code(
        $allIdProductAbstracts,
        $countryIso2Code
    );

    return $this->setItemsTax($itemTransfers, $taxRates);
}

This will fetch the correct taxrate by looking into the country code of the provided shipment address …

First a business related question: Why the taxrate gets calculated using the shipping address? Isn’t taxrate something that is specific for a certain country? So when i order as a german customer with a de iso2code in an asian shop, i assume i should not pay german taxes, right? So why the countrycode of the shipping address is relevant here?

Second is a technical one: Where can i set the shipping address (iso2code) that the taxes are calculated correctly?
Currently the shipping address is not set because there is never a opportunity to do that in a typical glue wrokflow where you first create a cart and than add an item … non of these endpoints let me set an address
Currently the item taxrate always falls back to the default one which is 19% which is wrong in every case.

Best

Comments

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 🧑🏻‍🚀 - Cadet

    I can suggest an answer to the second question. There is a /checkout-data endpoint, you can submit the shipping address to it. It does not return the quote in response, but the quote will get updated with shipping address in the process of the execution.

    You’ll have to see if this works though because the shipping address is not something that is being persisted with the quote, so it might get “lost” when you GET the cart after the /checkout-data.

    It it does not, it’s a good candidate for a bug/feature request/FD report

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet

    Hi Eugenia, thanks for your fast response. I really wonder that I am the first who get this trouble because for me thats a very very standard use case to get correct prices in my cart when i add something to it.
    I check your suggestion but i think - as you already mentioned - the shipping transfer will get lost when retrieving the cart …
    So far the tax rate calculation is some really weird to me …
    Best

  • Andriy Netseplyayev
    Andriy Netseplyayev Sprykee Posts: 519 🧑🏻‍🚀 - Cadet
    edited August 2020

    @UQKSAARKN Shouldn’t be persisted once you add the “shipping address” to \Spryker\Zed\Quote\QuoteConfig::getQuoteFieldsAllowedForSaving() ?

  • Andriy Netseplyayev
    Andriy Netseplyayev Sprykee Posts: 519 🧑🏻‍🚀 - Cadet

    First a business related question

    I think the US is the reason, and tax rate calculation between different states

  • Eugenia Poidenko
    Eugenia Poidenko Sprykee Posts: 145 🧑🏻‍🚀 - Cadet

    You might need to check also the transfer QuoteUpdateRequestAttributes. As I know you’ve to have the attribute there for persisting to work correctly

  • Andriy Netseplyayev
    Andriy Netseplyayev Sprykee Posts: 519 🧑🏻‍🚀 - Cadet

    as another solution I would think of providing the field you need (iso2code) directly to the quote object, specifically for tax calculation reasons and won’t stick to the shipping address, if that’s possible. The question is, can you determine that iso2code in the moment, when you create a cart (you should, otherwise, how will you calculate tax) ?

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet

    Along the cart would be absolutely fine

  • UPWG9AYH2
    UPWG9AYH2 Posts: 509 🧑🏻‍🚀 - Cadet
    edited August 2020

    but i could imagine that there will be some mix … one some places, address gets considered on other the quote … so i have to overwrite the deprecated ProductItemTaxRateCalculator in any case

  • Andriy Netseplyayev
    Andriy Netseplyayev Sprykee Posts: 519 🧑🏻‍🚀 - Cadet

    yes, there might be edge-cases in that solution I proposed: customer chooses another address, quote is getting merged, etc - you might also want to confirm with business if there could be simple solution to avoid tech over-complexity