2

I am using Magento 2.0.4 and finding a way to automatically mark the order status to 'Complete' once the payment is complete.

At the moment what is happening is once the payment is complete the order status is marked as 'Processing' and once the admin opens the order and provide some comments and submit the order becomes 'Complete'

I do not want admin to do this manually. How can I complete the order as soon as the customer complete their payment.

0

1 Answer 1

3

As in magento2 there is no functionality to change order status to complete when customer made the payment,but it can be done through observer.We have to use the event sales_order_place_after in events.xml file.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_order_place_after">
        <observer name="order_change_status" instance="Namesapce\Modulname\Model\File" shared="false" />
    </event>
</config>

In File.php use below code

$order = $observer->getEvent()->getOrder();
$order_status = $this->_objectManager->get('Magento\Sales\Model\Order')->load($order->getId());
$order_status->setStatus('complete');
$order_status->save();
2
  • Thanks. It looks like your solution requires to edit the Magento core files which I don't want to do that. Can this code put on a separate module? Commented Apr 5, 2016 at 19:37
  • yes you have to put this code in your separate module..as changing core files may create problem at the time of placing order Commented Apr 6, 2016 at 7:50

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.