0

I am using Website Payments Pro Payflow Edition for my store and wanted to know if there is a way to automatically change the order status from Processing to Ready to ship if the transaction it successful as currently our admin is having to do this manually.

I was thinking to use an Observer to change the status but so far I can only find the event to invoice:

<?php

class MyCompany_OrdersObserver_Model_Observer {

    public $order;//the order...

    function afterSalesOrderSaveCommitAfter(&$event) {
        return $this->__process($event);
    }

    protected function __process($event) {
        $this->order = $event->getEvent()->getOrder();
        if (!$this->order->getId()) {
            //order is not saved in the database
            return $this;
        }
        else {

            $this->createInvoice();
        }
    }

    protected function createInvoice() {
        $orderState = $this->order->getState();
        if ($orderState === Mage_Sales_Model_Order::STATE_NEW) { // Check for state new.
            if ($this->order->canInvoice()) {
                $this->order->getPayment()->setSkipTransactionCreation(false);
                $invoice = $this->order->prepareInvoice();
                $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
                $invoice->register();
                Mage::getModel('core/resource_transaction')
                   ->addObject($invoice)
                   ->addObject($this->order)
                   ->save();
            }
            else {
                //we can not invoice it so the process is normal.
            }
        }
    }
}

Is there another event I could use to achieve this? Or is it a configuration issue?

Any advice would be greatly appreciated

1

Try the below code. It working Fine in my project

public function invoice($realOrderId)
{

    $order = Mage::getModel('sales/order')->load($realOrderId);
    try {
        if(!$order->canInvoice())
        {
            Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
        }

        $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();

        if (!$invoice->getTotalQty()) {
            Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
        }

        $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
        //Or you can use
       //$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
        $invoice->register();
        $transactionSave = Mage::getModel('core/resource_transaction')
            ->addObject($invoice)
            ->addObject($invoice->getOrder());
        $transactionSave->save();
        $order->setStatus("complete");
        $order->save();

    }
    catch (Mage_Core_Exception $e) {
    }

}
4
  • Thanyou, which event are you using? May 12 '14 at 16:24
  • I am using checkout_onepage_controller_success_action event.
    – Keyul Shah
    May 12 '14 at 16:27
  • Thankyou, and is your method is invoice? May 12 '14 at 16:58
  • no observer method is diff but I call this method in from observer method
    – Keyul Shah
    May 13 '14 at 0:34

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.