Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get magento shipping tax rate from order object

I need to know how I get the tax rate of an order. Currently I'm calculation this value with

$order->getShippingTaxAmount() and $order->getShippingAmount()

It's really, really ugly, but this works so far. But if there are no shipping cost, I don't get the tax rate. I need the rate for an ERP-system to do other tasks.

I've tried to use "var_dump()" for the order object and looked for my value by searching the tax rate, but can't find anything. Another idea was "get_class_methods", but also no luck.

I know, there is another thread (#6940246), but the solution works "global" - I need the tax rate of a specific order, which depends on country or customer - and should be historical.

like image 944
Stefan Brendle Avatar asked May 16 '13 11:05

Stefan Brendle


People also ask

How do I get order shipping in Magento 2?

First, you need to configure the origin shipping method in Magento 2 to calculate the shipping costs for the shipments from your store and calculate the tax for your products. Go to Stores > Settings > Configuration > Sales > Delivery Methods (formerly Shipping Methods) and specify all the necessary details here.

What is tax rate in Magento?

Tax rate is a combination of tax zone (such as country, state or zip) and percentage. You can set up tax rates as shown in the following steps. Step 1 − Login to Magento Admin Panel. Step 2 − Go to Sales menu → Tax and click on the Manage Tax Zones & Rates option.


2 Answers

You can use $tax_info = $order->getFullTaxInfo(); This method comes directly from the order Model. It will give you an array containing detailed tax information for that order, including amount, tax code, title, tax id, percent.

To recieve e.g. the tax rate in percent, you can then use $tax_rate = $tax_info[0]['percent'];

like image 189
peter gunn Avatar answered Oct 04 '22 02:10

peter gunn


If you are in the 'quote' situation.

$store = $quote->getStore()
$taxCalculation = Mage::getModel('tax/calculation');
$request = $taxCalculation->getRateRequest(null, null, null, $store);
$taxRateId = Mage::getStoreConfig('tax/classes/shipping_tax_class', $store);

//taxRateId is the same model id as product tax classes, so you can do this:
$percent = $taxCalculation->getRate($request->setProductClassId($taxRateId));
like image 24
Daniel van der Garde Avatar answered Oct 04 '22 01:10

Daniel van der Garde