0

I want to change the new order status for Cash On Delivery Payment Method to Processing

I tried to do this:

I tried below changes in vendor but it didn't worked:

vendor\magento\module-offline-payments\etc\adminhtml\system.xml

<group id="cashondelivery" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Cash On Delivery Payment</label>
 ----                
<field id="order_status" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
     <label>New Order Status</label>
      <source_model>Magento\Sales\Model\Config\Source\Order\Status\Newprocessing</source_model>
OR
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
                </field>
---
</group>

Then I change in:

vendor\magento\module-offline-payments\etc\config.xml

<cashondelivery>
   <active>0</active>
   <model>Magento\OfflinePayments\Model\Cashondelivery</model>
   <order_status>processing</order_status>
   <title>Cash On Delivery</title>
   <allowspecific>0</allowspecific>
   <group>offline</group>
</cashondelivery>

also did not help. how can this be achieved?

2

You can achieve this from admin and need one change on system.xml Add below code:

<source_model>Magento\Sales\Model\Config\Source\Order\Status\Newprocessing</source_model>

Instead of

<source_model>Magento\Sales\Model\Config\Source\Order\Status\NewStatus</source_model>

You will find the system.xml under

vendor/magento/module-offline-payments/etc/adminhtml/system.xml

Note: Direct edit on core is not a good practice you can copy/override these onto your theme and do the change.

Then follow the below steps:

Goto Store -> Configuration -> Sales -> Payment Methods

Under this you will find Other payment Methods click on that now you can see the Cash on delivery and other payment options.

Change the "New Order Status" status to processing. Check the screenshot.enter image description here

After doing all the changes please clean cache.

Thats it!

0

In vendor/magento/module-sales/Model/Order/Payment.php the order status is set to NEW while placing an order, So the order status is not changing to processing even if we set this from admin.

To resolve this I created a plugin for Magento\Sales\Model\ResourceModel\Order\Handler\State and changed the order status for the needed payment method.

Here I changed the order status to processing for Check Money Order orders.

Plugin Code:

<?php

namespace ABC\Test\Plugin\Order\Handler;

use Magento\Sales\Model\Order;

/**
 * Class State
 */
class State
{
    /**
     * Check order status and adjust the status before save for check money orders
     * @param \Magento\Sales\Model\ResourceModel\Order\Handler\State $subject
     * @param $result
     * @param Order $order
     * @return mixed
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function afterCheck(\Magento\Sales\Model\ResourceModel\Order\Handler\State $subject, $result,  Order $order)
    {

        if($order->getEntityType() == 'order' && $order->getPayment()->getMethod() == 'checkmo'){
            $order->setState(Order::STATE_PROCESSING)
                ->setStatus('processing');
        }

        return $result;
    }
}

di.xml :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Model\ResourceModel\Order\Handler\State">
        <plugin name="changingorderstatus" type="ABC\Test\Plugin\Order\Handler\State" sortOrder="100" disabled="false" />
    </type>
</config>

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.