#OrderService.decorateTotals() gives "can't read properties of undefined reading 'tax_provider_id'"

1 messages · Page 1 of 1 (latest)

formal nest
#

I used the OrderRepository to return a bunch of Order[] and want to decorate them with totals, so I used OrderService.decorateTotals() for each Order. However, I get:

TypeError: Cannot read properties of undefined (reading 'tax_provider_id')
    at TaxProviderService.retrieveProvider (/Users/zarar/dev/punchline-backend/node_modules/@medusajs/medusa/dist/services/tax-provider.js:103:20)

I am using a custom tax provider and it is configured correctly in the Admin section (the tax totals works just fine) but because of calculationContext.region being undefined in the tax-provider.ts, it throws an error when accessing region.tax_provider_id

How do I decorate individual orders with totals while using a custom tax provider?

honest mantle
#

Is your order missing a region maybe?

formal nest
#

I only have one region configured. Should the system not automatically pick that up as the region if only one is configured?

honest mantle
#

Not if you don’t tell typeorm to fetch the relation

#

You can look how it is done in retriveWithTotals for example

#

Because your order probably have a region id

#

If the region was automatically deduced, what would happen to the existing orders if you configured another region?

formal nest
#

That's a good point. I can confirm that the order is not missing a region and that the region_id column is pointing to a valid region. The error is happening in the tax provider file with the calculationContext not having a region in there.

#

maybe i need to do a join with the region table to get this going

honest mantle
#

Yes because it takes it from the argument. Which means that if you query the order without the relation then it is not there

#

Which is why i suggest you to look at the retrieveWithTotals to see what are the relations that are added