Skip to content

Commit

Permalink
Fixed logging too many exceptions for payment methods (OpenMage#3181)
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano authored Apr 28, 2023
1 parent f4855d4 commit 7664a35
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions app/code/core/Mage/Payment/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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'])) {
Expand Down

0 comments on commit 7664a35

Please sign in to comment.