Fooman Surcharge und PHP 7

In Magento, the Surcharge Extension makes it easy and convenient to charge surcharges for various areas of the online shop without having to modify Magento's built-in price rules to allow negative discounts. This can also be used for payment methods, for example, as a payment surcharge for cash on delivery, PayPal, and so on. With PHP 7, however, the display in the checkout changes—instead of the respective individual payment method surcharges, it simply displays "1" (+ currency).

 

 

If you search the system.log, you will quickly find the cause:

 

Notice: Object of class Fooman_Surcharge_Model_Surcharge could not be converted to int in app/code/community/Fooman/Surcharge/Model/Observer.php on line 263

 

and

 

Notice: Object of class Fooman_Surcharge_Model_Surcharge could not be converted to int in app/code/community/Fooman/Surcharge/Model/Observer.php on line 264

 

The culprit here is therefore the file \app\code\community\Fooman\Surcharge\Model\Observer.php, in which two lines cause the error.

 

In the _calcSurchargePreview($quote, $methodCode) function, replace the lines

 

$surcharge->setBaseAmount($surcharge->setBaseAmount() + $surcharge->getBaseTaxAmount());
$surcharge->setAmount($surcharge->setAmount() + $surcharge->getTaxAmount());

 

with

 

$surcharge->setBaseAmount($surcharge->getBaseAmount() + $surcharge->getBaseTaxAmount());
$surcharge->setAmount($surcharge->getAmount() + $surcharge->getTaxAmount());

 

and the error is fixed, with the surcharges now being displayed correctly. Tested with Magento CE 1.9.1.0.