0

Sometimes an order gets stuck at "Payment review" status/state, and there is no way to cancel it through Magento. From magento I only can change them to "suspect fraud" status/state but I can't cancel them.

I can cancel the orders editing directly in the database the order in the tables sales_flat_order and sales_flat_order_grid.

Is there a way to do it directly with magento? Do I need to add by code a cancel button to the orders in this status/state?

Magento ver. 1.9.2.4

2 Answers 2

1

Finally I made an override of the core model Mage_Sales_Model_Order.

To override this file, copy app/code/core/Mage/Sales/Model/Order.php to app/code/local/Mage/Sales/Model/Order.php

In the file placed in local, find the public function canCancel() (over the line 545) and add to the beginning of the function:

if ($this->isPaymentReview()) {
    return true;
}

Now the cancel button is displayed on payment review status/state orders, and this way I'm able to cancel this orders.

0

Below code worked for me.

 private function cancelPendingPayments() {

    $fromDate = date('Y-m-d H:i:s', strtotime('-2 hour'));
    $toDate = date('Y-m-d H:i:s', strtotime(now()));
    $orderCollection = Mage::getResourceModel('sales/order_collection');

    $orderCollection->addFieldToFilter('status', 'pending_payment')
        ->addFieldToFilter('updated_at',  array( 'from' => $fromDate, 'to' => $toDate, 'date' => true ))
        ->getSelect()
        ->order('entity_id')
        ->limit(20);

    if( count( $orderCollection ) < 1 )  {
        return;
    }

    foreach( $orderCollection as $order ) {

        $difference = $this->getDifference($order);
        if( ( $difference >= 30 ) && ( $difference < 45 ) ) {

            $emailVariables = $this->pendingPaymentsVariables( $order );

            $this->prepareEmail( Mage::getStoreConfig('clearbasket_settings/email_template/pending_payment_notify'),
                                 $emailVariables, $emailVariables['orderdetails']['customername'], $emailVariables['orderdetails']['customeremail'] );
           $history = $order->addStatusHistoryComment('Notification email sent - Cron Jobs',false);
           $history->setIsCustomerNotified(false);
           $order->save();
        }

        if( $difference > 60 ) {

             if(!$order->canCancel()) {
                  Mage::log('Order cannot be canceled anymore.',null,"order.log");
              }
              else {
               $order->cancel();
    }
            $order->setData('state', "canceled");
            $order->setStatus("canceled");
            $order->setData('state', Mage_Sales_Model_Order::STATE_CANCELED); 
            $order->setActionFlag(Mage_Sales_Model_Order::ACTION_FLAG_CANCEL, true);
            Mage::log('Order cancel after : '.$difference, null, "order.log");
            $history = $order->addStatusHistoryComment('Order marked as cancelled due to pending payment - Cron Jobs.', false);
            $history->setIsCustomerNotified(false);
            $order->save();
        }

    }

}

Please refer the link below for sending notification emails before cancelling and cron jobs. https://www.pearlbells.co.uk/cancel-pending-payments-magento/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.