I want all available shipping methods list with shipping rates and Tax amount.
I've done below function, though it's giving me shipping methods list with rates but not shipping tax amount per shipping method on cart page
public function getShippingDetails($quote)
{
$output = [];
if (! $quote->isVirtual()) {
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setCollectShippingRates(true);
$this->_totalsCollector->collectAddressTotals($quote, $shippingAddress);
$shippingRates = $shippingAddress->getGroupedAllShippingRates();
foreach ($shippingRates as $carrierRates) {
foreach ($carrierRates as $rate) {
$output[] = $this->_converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode());
}
}
}
return $output;
}
It returns
[{
"carrier_code": "freeshipping",
"method_code": "freeshipping",
"carrier_title": "Free Shipping",
"method_title": "Free",
"amount": 0,
"base_amount": 0,
"available": true,
"error_message": "",
"price_excl_tax": 0,
"price_incl_tax": 0
}, {
"carrier_code": "flatrate",
"method_code": "flatrate",
"carrier_title": "Flat Rate",
"method_title": "Fixed",
"amount": 5,
"base_amount": 5,
"available": true,
"error_message": "",
"price_excl_tax": 5,
"price_incl_tax": 5
}]
The shipping Tax applied 10% , however I'm getting $5 in price_incl_tax for flatrate instead of 5.5 I've tried to fetch the price with tax with below code as well but didn't work
/**
* Tax data
*
* @var \Magento\Tax\Helper\Data
*/
protected $_taxData;
$amount =(double)$rate->getPrice();
$amountInclTax=$this->_taxData->getShippingPrice($amount, true, $shippingAddress);
$amountExclTax=$this->_taxData->getShippingPrice($amount, false, $shippingAddress);
Can anyone please help me ,how I can get shipping rates with shipping tax amount?
Thanks