Since the order method getFullTaxInfo()
is not available in Magento 2, how does one get the tax percent used on the order shipping amount for an order?
I see the item is in sales_order_tax_item
table (where taxable_item_type = shipping), but I don't see any method in the Order or OrderInterface for fetching the tax details, except what is already in the Order table columns (tax amount, etc.).
Weirdly enough this table also does not contain an order_id column, so there's no direct back-reference.
I know you can calculate the percentage manually but I think it's best to avoid it.
I see a promising method
\Magento\Sales\Model\ResourceModel\Order\Tax::getTaxItemsByOrderId($orderId)
but I have no idea how to properly use it.
Best Answer
I figured it out... Here's an example.
Returns an array in format:
So just iterate through and test if
taxable_item_type
equals to 'shipping':I also had to recompile DI with
setup:di:compile
in CLI.