Skip to content

Commit 1f8db2d

Browse files
authored
Added ability to view orders paid with removed payment method without breaking (OpenMage#15)
1 parent 2c84338 commit 1f8db2d

File tree

6 files changed

+38
-12
lines changed

6 files changed

+38
-12
lines changed

.phpstan.baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3865,11 +3865,6 @@ parameters:
38653865
count: 1
38663866
path: app/code/core/Mage/Sales/Model/Order/Payment.php
38673867

3868-
-
3869-
message: "#^Property Mage_Sales_Model_Order_Payment\\:\\:\\$_canVoidLookup \\(string\\) does not accept bool\\.$#"
3870-
count: 2
3871-
path: app/code/core/Mage/Sales/Model/Order/Payment.php
3872-
38733868
-
38743869
message: "#^Method Mage_Sales_Model_Order_Payment_Transaction\\:\\:getOrderId\\(\\) should return int\\|null but return statement is missing\\.$#"
38753870
count: 1

app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,12 @@ public function canEditQty()
449449
) {
450450
return false;
451451
}
452-
if ($this->getOrder()->getPayment()->canCapture()) {
453-
return $this->getOrder()->getPayment()->canCapturePartial();
452+
$payment = $this->getOrder()->getPayment();
453+
if ($payment
454+
&& $this->helper('payment')->getMethodModelClassName($payment->getMethod()) !== null
455+
&& $payment->canCapture()
456+
) {
457+
return $payment->canCapturePartial();
454458
}
455459
return true;
456460
}

app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function __construct()
162162

163163
if ($this->_isAllowedAction('creditmemo') && $order->canCreditmemo()) {
164164
$onClick = Mage::helper('core/js')->getSetLocationJs($this->getCreditmemoUrl());
165-
if ($order->getPayment()->getMethodInstance()->isGateway()) {
165+
if ($order->getPayment() && $order->getPayment()->getMethodInstance()->isGateway()) {
166166
$onClick = Mage::helper('core/js')->getConfirmSetLocationJs(
167167
$this->getCreditmemoUrl(),
168168
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?')

app/code/core/Mage/Payment/Helper/Data.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,20 @@ public function getMethodFormBlock(Mage_Payment_Model_Method_Abstract $method)
120120
*
121121
* @return Mage_Core_Block_Template|Mage_Core_Block_Abstract
122122
*/
123-
public function getInfoBlock(Mage_Payment_Model_Info $info)
123+
public function getInfoBlock(Mage_Payment_Model_Info|false $info)
124124
{
125-
$blockType = $info->getMethodInstance()->getInfoBlockType();
125+
$method = $info === false ? $this->__('No Data Found') : $info->getMethod();
126+
if ($this->getMethodModelClassName($method) !== null) {
127+
$blockType = $info->getMethodInstance()->getInfoBlockType();
128+
} else {
129+
Mage::log(
130+
sprintf('Payment method was not found: %s', $method),
131+
Zend_Log::NOTICE
132+
);
133+
return ($this->getLayout() ?? Mage::app()->getLayout())
134+
->createBlock('core/text')
135+
->setText($method);
136+
}
126137
if ($this->getLayout()) {
127138
$block = $this->getLayout()->createBlock($blockType);
128139
} else {

app/code/core/Mage/Sales/Model/Order.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ public function canCancel()
671671
*/
672672
public function canVoidPayment()
673673
{
674+
if ($this->getPayment() === false) {
675+
return false;
676+
}
674677
return $this->_canVoidOrder() ? $this->getPayment()->canVoid($this->getPayment()) : false;
675678
}
676679

@@ -841,7 +844,16 @@ public function canEdit()
841844
return false;
842845
}
843846

844-
if (!$this->getPayment()->getMethodInstance()->canEdit()) {
847+
$payment = $this->getPayment();
848+
if (!$payment) {
849+
return false;
850+
}
851+
852+
if (Mage::helper('payment')->getMethodModelClassName($payment->getMethod()) === null) {
853+
return false;
854+
}
855+
856+
if (!$payment->getMethodInstance()->canEdit()) {
845857
return false;
846858
}
847859

app/code/core/Mage/Sales/Model/Order/Payment.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class Mage_Sales_Model_Order_Payment extends Mage_Payment_Model_Info
221221

222222
/**
223223
* Whether can void
224-
* @var string
224+
* @var bool|null
225225
*/
226226
protected $_canVoidLookup = null;
227227

@@ -650,6 +650,10 @@ protected function _invoice()
650650
public function canVoid(Varien_Object $document)
651651
{
652652
if ($this->_canVoidLookup === null) {
653+
if (Mage::helper('payment')->getMethodModelClassName($this->getMethod()) === null) {
654+
$this->_canVoidLookup = false;
655+
return $this->_canVoidLookup;
656+
}
653657
$this->_canVoidLookup = (bool)$this->getMethodInstance()->canVoid($document);
654658
if ($this->_canVoidLookup) {
655659
$authTransaction = $this->getAuthorizationTransaction();

0 commit comments

Comments
 (0)