cancel
Showing results for 
Search instead for 
Did you mean: 

Rounding item total

Rounding item total

Hi

I need to rounding the cart item totals only both mini cart and one page checkout.

https://prnt.sc/0cmFExsbC_C6

 

1 REPLY 1

Re: Rounding item total

Hello @sainulabidnv 

 

To round the cart item totals in both the mini cart and one-page checkout in Magento 2, please follow the steps below:

  1. Open Magento 2 project in your preferred code editor.
  2. Locate the file vendor/magento/module-tax/Model/Sales/Total/Quote/Tax.php.
  3. Search for the following code block:
    $baseTaxDetails = $item->getBaseTaxCalculationDetails();
    $taxDetails = $item->getTaxCalculationDetails();
    and replace the above code block with the following code block:
    $baseTaxDetails = $item->getBaseTaxCalculationDetails();
    		$taxDetails = $item->getTaxCalculationDetails();
    		// Rounding tax amount
    		$precision = 2; // Change the precision as per your requirement
    		$baseTaxAmount = round($item->getBaseTaxAmount(), $precision);
    		$taxAmount = round($item->getTaxAmount(), $precision);
    		$baseTaxDetails['tax'] = $baseTaxAmount;
    		$taxDetails['tax'] = $taxAmount;
    4. Save the file and clear the cache.

    This will round the tax amount to the specified precision for each item in the cart, 

    which will be reflected in both the mini cart and one-page checkout.

If you find our reply helpful, please give us kudos.

 

A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.

 

WebDesk Solution Support Team

Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789

Thank You,


WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789


Location: 150 King St. W. Toronto, ON M5H 1J9