Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to view orders paid with removed payment method without breaking #15

Merged
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
7 changes: 5 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,11 @@ public function canEditQty()
) {
return false;
}
if ($this->getOrder()->getPayment()->canCapture()) {
return $this->getOrder()->getPayment()->canCapturePartial();
if (($payment = $this->getOrder()->getPayment())
tmewes marked this conversation as resolved.
Show resolved Hide resolved
&& Mage::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 ? $info->getMethod() : $this->__('No Data Found');
fballiano marked this conversation as resolved.
Show resolved Hide resolved
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
8 changes: 7 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) {
fballiano marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
return $this->_canVoidOrder() ? $this->getPayment()->canVoid($this->getPayment()) : false;
}

Expand Down Expand Up @@ -841,7 +844,10 @@ public function canEdit()
return false;
}

if (!$this->getPayment()->getMethodInstance()->canEdit()) {
if (!($payment = $this->getPayment())
|| Mage::helper('payment')->getMethodModelClassName($payment->getMethod()) === null
|| !$payment->getMethodInstance()->canEdit()
) {
tmewes marked this conversation as resolved.
Show resolved Hide resolved
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