diff --git a/.phpstan.baseline.neon b/.phpstan.baseline.neon index 62e9062b7..a1204d964 100644 --- a/.phpstan.baseline.neon +++ b/.phpstan.baseline.neon @@ -3865,11 +3865,6 @@ parameters: count: 1 path: app/code/core/Mage/Sales/Model/Order/Payment.php - - - message: "#^Property Mage_Sales_Model_Order_Payment\\:\\:\\$_canVoidLookup \\(string\\) does not accept bool\\.$#" - count: 2 - path: app/code/core/Mage/Sales/Model/Order/Payment.php - - message: "#^Method Mage_Sales_Model_Order_Payment_Transaction\\:\\:getOrderId\\(\\) should return int\\|null but return statement is missing\\.$#" count: 1 diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php index 40690d523..4a5794355 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php @@ -449,8 +449,12 @@ public function canEditQty() ) { return false; } - if ($this->getOrder()->getPayment()->canCapture()) { - return $this->getOrder()->getPayment()->canCapturePartial(); + $payment = $this->getOrder()->getPayment(); + if ($payment + && $this->helper('payment')->getMethodModelClassName($payment->getMethod()) !== null + && $payment->canCapture() + ) { + return $payment->canCapturePartial(); } return true; } diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php index f99b2220c..36021263b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php @@ -162,7 +162,7 @@ public function __construct() if ($this->_isAllowedAction('creditmemo') && $order->canCreditmemo()) { $onClick = Mage::helper('core/js')->getSetLocationJs($this->getCreditmemoUrl()); - if ($order->getPayment()->getMethodInstance()->isGateway()) { + if ($order->getPayment() && $order->getPayment()->getMethodInstance()->isGateway()) { $onClick = Mage::helper('core/js')->getConfirmSetLocationJs( $this->getCreditmemoUrl(), Mage::helper('sales')->__('This will create an offline refund. To create an online refund, open an invoice and create credit memo for it. Do you wish to proceed?') diff --git a/app/code/core/Mage/Payment/Helper/Data.php b/app/code/core/Mage/Payment/Helper/Data.php index 18666b300..2a1e6d6da 100644 --- a/app/code/core/Mage/Payment/Helper/Data.php +++ b/app/code/core/Mage/Payment/Helper/Data.php @@ -120,9 +120,20 @@ public function getMethodFormBlock(Mage_Payment_Model_Method_Abstract $method) * * @return Mage_Core_Block_Template|Mage_Core_Block_Abstract */ - public function getInfoBlock(Mage_Payment_Model_Info $info) + public function getInfoBlock(Mage_Payment_Model_Info|false $info) { - $blockType = $info->getMethodInstance()->getInfoBlockType(); + $method = $info === false ? $this->__('No Data Found') : $info->getMethod(); + if ($this->getMethodModelClassName($method) !== null) { + $blockType = $info->getMethodInstance()->getInfoBlockType(); + } else { + Mage::log( + sprintf('Payment method was not found: %s', $method), + Zend_Log::NOTICE + ); + return ($this->getLayout() ?? Mage::app()->getLayout()) + ->createBlock('core/text') + ->setText($method); + } if ($this->getLayout()) { $block = $this->getLayout()->createBlock($blockType); } else { diff --git a/app/code/core/Mage/Sales/Model/Order.php b/app/code/core/Mage/Sales/Model/Order.php index 162f81440..d88840bb5 100644 --- a/app/code/core/Mage/Sales/Model/Order.php +++ b/app/code/core/Mage/Sales/Model/Order.php @@ -671,6 +671,9 @@ public function canCancel() */ public function canVoidPayment() { + if ($this->getPayment() === false) { + return false; + } return $this->_canVoidOrder() ? $this->getPayment()->canVoid($this->getPayment()) : false; } @@ -841,7 +844,16 @@ public function canEdit() return false; } - if (!$this->getPayment()->getMethodInstance()->canEdit()) { + $payment = $this->getPayment(); + if (!$payment) { + return false; + } + + if (Mage::helper('payment')->getMethodModelClassName($payment->getMethod()) === null) { + return false; + } + + if (!$payment->getMethodInstance()->canEdit()) { return false; } diff --git a/app/code/core/Mage/Sales/Model/Order/Payment.php b/app/code/core/Mage/Sales/Model/Order/Payment.php index f6481a8bc..3a5d429c3 100644 --- a/app/code/core/Mage/Sales/Model/Order/Payment.php +++ b/app/code/core/Mage/Sales/Model/Order/Payment.php @@ -221,7 +221,7 @@ class Mage_Sales_Model_Order_Payment extends Mage_Payment_Model_Info /** * Whether can void - * @var string + * @var bool|null */ protected $_canVoidLookup = null; @@ -650,6 +650,10 @@ protected function _invoice() public function canVoid(Varien_Object $document) { if ($this->_canVoidLookup === null) { + if (Mage::helper('payment')->getMethodModelClassName($this->getMethod()) === null) { + $this->_canVoidLookup = false; + return $this->_canVoidLookup; + } $this->_canVoidLookup = (bool)$this->getMethodInstance()->canVoid($document); if ($this->_canVoidLookup) { $authTransaction = $this->getAuthorizationTransaction();