0

I want to use one offline payment method module, I install this module

is there any way to change the status of the order to be Processing instead of Pending? Right now all my orders have status Pending and I really need to be Processing.

Thank you

1
  1. create app\code\Vendor\Extension\etc\events.xml with the following code.

    <?xml version="1.0"?>
    <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="vendor_sales_order_place_after" instance="Vendor\Extensoin\Observer\OrderObserver" />
        </event>
    </config>
    
  2. you need to create Observer file at following location.

    app\code\Vendor\Extension\Observer\OrderObserver.php
    
    
    <?php
    namespace Vendor\Extension\Observer;
    
    use Magento\Framework\Event\ObserverInterface;
    
    class OrderObserver implements ObserverInterface
    {
       public function execute(\Magento\Framework\Event\Observer $observer)
       {
         $order = $observer->getEvent()->getOrder();
         //NOW APPLY YOUR LOGIC HERE TO CHECK ORDER PAYMENT METHOD AND BASED ON THAT CHANGE THERE STATUS
       }
     }
    
1
  • Hi, your code is not work is redirect back to the Shopping Cart page ...
    – Robert
    Aug 30 '21 at 6:17
0
  1. Add bellow code in your custom module etc\events.xml
<event name="sales_order_place_after">
   <observer name="custom_sales_order_place_after" instance="Vendor\Module\Observer\CustomOrderObserver" />
</event>
  1. Create CustomOrderObserver file
<?php
namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;

class CustomOrderObserver implements ObserverInterface
{
   public function execute(\Magento\Framework\Event\Observer $observer)
   {
     $order = $observer->getEvent()->getOrder();
     $order->setStatus('processing);
   }
 }
1
  • Hi, is not work, after I place the code where you say My checkout page is redirect back to Shopping Cart page, you have any idea why?
    – Robert
    Aug 27 '21 at 6:51

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.