0

I updated my php version is 8.3 and magento version is 2.4.6 currently facing issue with round functionality.

Exception message: Deprecated Functionality: round(): Passing null to parameter #1 ($num) of type int|float is deprecated

Fee.php

$amount = $invoice->getHandlingCharges();
        $amount += round($invoice->getHandlingChargesTax(), 3, PHP_ROUND_HALF_UP);

        $baseAmount = $invoice->getBaseHandlingCharges();
        $baseAmount += round($invoice->getBaseHandlingChargesTax(), 3, PHP_ROUND_HALF_UP);

        $invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
        $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseAmount);

        return $this;

please help

2 Answers 2

0

The exception was thrown because of null value passed to php round function.

These lines

   $amount += round($invoice->getHandlingChargesTax(), 3, PHP_ROUND_HALF_UP);
   $baseAmount += round($invoice->getBaseHandlingChargesTax(), 3, PHP_ROUND_HALF_UP)

should be replaced with

$amount += ($invoice->getHandlingChargesTax()) ? round($invoice->getHandlingChargesTax(), 3, PHP_ROUND_HALF_UP) : 0;

$baseAmount += ($invoice->getBaseHandlingChargesTax()) ? round($invoice->getBaseHandlingChargesTax(), 3, PHP_ROUND_HALF_UP) : 0;
    
0

To change your round function to handle null parameters like this, add ??""

round($invoice->getHandlingChargesTax()??"", 3, PHP_ROUND_HALF_UP);

Wherever you get a null exception, do this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.