How to display order status to pending option in my offline payment method in magento 2.4?

Viewed 523

What I am trying to do is to display option like below screenshot in my custom offline payment module: enter image description here

However, the red box is not appearing on my offline payment method option inside the admin store>configuration>payment method> custom payment

My code in system.xml file is as below:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
    <section id="payment">
            <group id="offlinepaymentext" translate="label" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Offilne Payment Extension</label>
                <field id="active" translate="label comment" sortOrder="1" type="select" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Enable</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                
                <label>New Order Status</label>
                <field id="order_status" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
                    <label>Pending</label>
                    <source_model>Magento\Sales\Model\Config\Source\Order\Status\Pending</source_model>
                </field>
                
                
            </group>
    </section>   
</system>
</config>

Also, I don;t want NewProcessing or processing but instead of I want Pending status inside the dropdown.

My config.xml file look like below:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../Store/etc/config.xsd">
<default>
    <payment>
        <offlinepaymentext>
            <payment_action>capture</payment_action><!-- You can use another methor like capture  -->
            <model>OfflinePayment\Ext\Model\PaymentMethod</model>
            <active>1</active>
            <title>Offline Payment</title>
            <order_status>pending</order_status><!-- set default order status pending_payment-->
        </offlinepaymentext>
    </payment>
</default>
</config>

I am new to magento 2 and don't know how to add this option in my custom payment module.

after making all the above changes my admin section of magento display like below(admin>stores>configurations>Sales>PAyment Methods) enter image description here

Any idea? what I am doing wrong here?

1 Answers

If I understand you want to have a multiple-choice option in the dropdown from the (New Order Status) field?

In that case, you need to put on your system.xml source_model this class: Magento\Sales\Model\Config\Source\Order\Status or extend this class and add in $_stateStatuses new ones.

system.xml code -> https://i.stack.imgur.com/0AmDs.jpg result admin -> https://i.stack.imgur.com/Al4a0.jpg

Related