2

I have a Magento EE 1.14.0.1 and am working on a custom paypal type payment processor.

I have it all working with the exception of if once a customer gets to the external payment processors page and clicks the cancel button I have code that will when they come back to the site convert their order to a quote and direct them to their view cart page. However the order is still staying listed in the sales order page as "pending. However I want to have it removed from the sales order listing page since it has been converted back to a quote and is no longer an order.

below is the code I am using to take the order and convert it back to a quote I am not sure what to add or alter.

   $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
        if ($quote->getId()) {
                                $quote->setIsActive(1)
                                    //->setReservedOrderId(null)
                                      ->save();

                                Mage::getSingleton('checkout/session')
                                           ->replaceQuote($quote);
                                        // ->unsLastRealOrderId();
                                                }
                                $this->_redirect('checkout/cart');
                             }

What I want is after the order is converted to a quote to DELETE the order from being listed in the sales order page not just have it listed as cancelled.

1
public function cancelAction()
{
    $session = Mage::getSingleton('checkout/session');
    if ($session->getLastRealOrderId())
    {
        $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
        if ($order->getId())
        {
            //Cancel order
            if ($order->getState() != Mage_Sales_Model_Order::STATE_CANCELED)
            {
                $order->registerCancellation("Canceled by Payment Provider")->save();
            }
            $quote = Mage::getModel('sales/quote')
                ->load($order->getQuoteId());
            //Return quote
            if ($quote->getId())
            {
                $quote->setIsActive(1)
                    ->setReservedOrderId(NULL)
                    ->save();
                $session->replaceQuote($quote);
            }

            //Unset data
            $session->unsLastRealOrderId();
        }
    }

    return $this->getResponse()->setRedirect( Mage::getUrl('checkout/cart'));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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