From 7664a3532d3b3be3aebccd41b2506a1e1298ac2e Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Fri, 28 Apr 2023 11:12:44 +0100 Subject: [PATCH] Fixed logging too many exceptions for payment methods (#3181) --- app/code/core/Mage/Payment/Helper/Data.php | 28 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/code/core/Mage/Payment/Helper/Data.php b/app/code/core/Mage/Payment/Helper/Data.php index d05dd380f52..5f6f6da6570 100644 --- a/app/code/core/Mage/Payment/Helper/Data.php +++ b/app/code/core/Mage/Payment/Helper/Data.php @@ -26,6 +26,18 @@ class Mage_Payment_Helper_Data extends Mage_Core_Helper_Abstract protected $_moduleName = 'Mage_Payment'; + /** + * Retrieve the class name of the payment method's model + * + * @param $code + * @return string|null + */ + public function getMethodModelClassName($code) + { + $key = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/model'; + return Mage::getStoreConfig($key); + } + /** * Retrieve method model object * @@ -34,8 +46,7 @@ class Mage_Payment_Helper_Data extends Mage_Core_Helper_Abstract */ public function getMethodInstance($code) { - $key = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/model'; - $class = Mage::getStoreConfig($key); + $class = $this->getMethodModelClassName($code); if (is_null($class)) { Mage::logException(new Exception(sprintf('Unknown payment method with code "%s"', $code))); return false; @@ -156,7 +167,13 @@ public function getRecurringProfileMethods($store = null) { $result = []; foreach ($this->getPaymentMethods($store) as $code => $data) { - $method = $this->getMethodInstance($code); + $paymentMethodModelClassName = $this->getMethodModelClassName($code); + if (!$paymentMethodModelClassName) { + continue; + } + + /** @var Mage_Payment_Model_Method_Abstract $method */ + $method = Mage::getModel($paymentMethodModelClassName); if ($method && $method->canManageRecurringProfiles()) { $result[] = $method; } @@ -207,8 +224,9 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit if ((isset($data['title']))) { $methods[$code] = $data['title']; } else { - if ($this->getMethodInstance($code)) { - $methods[$code] = $this->getMethodInstance($code)->getConfigData('title', $store); + $paymentMethodModelClassName = $this->getMethodModelClassName($code); + if ($paymentMethodModelClassName) { + $methods[$code] = Mage::getModel($paymentMethodModelClassName)->getConfigData('title', $store); } } if ($asLabelValue && $withGroups && isset($data['group'])) {