0

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

1 Answer 1

0

Navigate to STORES > Settings > Configuration then expand the SALES panel and select Tax Expand the Tax Classes panel In the Tax Class for Shipping drop-down menu you will chose the option:“Taxable Goods”

Expand the Calculation Settings panel

You’ll see that one of the fields is a "Shipping Prices" drop-down menu. This is where you can choose whether you would like to charge tax for shipping.

Expand the Default Tax Destination Calculation panel. This will determine the destination location for determining your tax rate.

Default Country Default State Default Post Code Expand the Price Display Settings panel to determine how prices will be displayed in your store. Display Product Prices In Catalog:

“Excluding Tax” “Including Tax” “Including and Excluding Tax” Display Shipping Prices:

“Excluding Tax” “Including Tax” “Including and Excluding Tax” Expand the Shopping Cart Display Settings` panel to determine how prices will be displayed in your shopping cart.

Display Shipping Prices:“Including Tax”

Expand the Shopping Cart Display Settings` panel to determine how prices will be displayed in your shopping cart.

Display Prices:“Including Tax”

Display Subtotal:“Including Tax”

Display Shipping Amount:“Including Tax”

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.