Skip to content

Commit

Permalink
Added ability to view orders paid with removed payment method without…
Browse files Browse the repository at this point in the history
… breaking (#15)
  • Loading branch information
tmewes authored Sep 12, 2024
1 parent 2c84338 commit 1f8db2d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
5 changes: 0 additions & 5 deletions .phpstan.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions app/code/core/Mage/Adminhtml/Block/Sales/Items/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?')
Expand Down
15 changes: 13 additions & 2 deletions app/code/core/Mage/Payment/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion app/code/core/Mage/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion app/code/core/Mage/Sales/Model/Order/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1f8db2d

Please sign in to comment.