3

I have created a custom payment method module.

System configuration has a field for selecting New order status.

Even if I set it as "Pending", new order status is showing as "processing".

Please help..

namespace/module/etc/adminhtml/system.xml

<system>
        <section id="payment">
            <group id="zipcodpayment" translate="label" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Zip Limited COD Payment</label>
                <field id="active" translate="label comment" sortOrder="1" type="select" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enable</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="title" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Title</label>
                </field>
                <field id="order_status" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>New Order Status</label>
                    <source_model>Magento\Sales\Model\Config\Source\Order\Status\NewStatus</source_model>
                </field>             
                <field id="allowspecific" translate="label" type="allowspecific" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Payment from Applicable Countries</label>
                    <source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
                </field>
                <field id="specificcountry" translate="label" type="multiselect" sortOrder="41" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Payment from Specific Countries</label>
                    <source_model>Magento\Directory\Model\Config\Source\Country</source_model>
                    <can_be_empty>1</can_be_empty>
                </field>
            </group>
        </section>
    </system>
4
  • which status have you selected from Store->configuration->sales->payment method -> {your custom_method}-> new order status ? Dec 13, 2016 at 11:55
  • I have selected "pending"..but still order status remains as "processing".
    – D.T
    Dec 13, 2016 at 11:57
  • check in your store->order status what is the pending and processing State Code And Title. Dec 13, 2016 at 12:02
  • Can you please let me know how you resolve this issue?
    – mjdevloper
    Jan 11, 2017 at 13:00

3 Answers 3

11

In your payment method model you can add

protected $_isInitializeNeeded = true;

In Magento\Sales\Model\Order\Payment, you will see :

public function place()
{
    ....

    if ($methodInstance->isInitializeNeeded()) {
        $stateObject = new \Magento\Framework\DataObject();
        // For method initialization we have to use original config value for payment action
        $methodInstance->initialize($methodInstance->getConfigData('payment_action'), $stateObject);
        $orderState = $stateObject->getData('state') ?: $orderState;
        $orderStatus = $stateObject->getData('status') ?: $orderStatus;
        $isCustomerNotified = $stateObject->hasData('is_notified')
                    ? $stateObject->getData('is_notified')
                    : $isCustomerNotified;
    } else {
        $orderState = Order::STATE_PROCESSING;
        $this->processAction($action, $order);
        $orderState = $order->getState() ? $order->getState() : $orderState;
        $orderStatus = $order->getStatus() ? $order->getStatus() : $orderStatus;
    }

    ....
}

so if $methodInstance->isInitializeNeeded() is false , the orderstate will be Order::STATE_PROCESSING;instead of what you configured in the system backend .

1
  • In my case, I also had to override 'payment_action' config, to return 'authorize_capture'... public function getConfigPaymentAction() { return 'authorize_capture'; }... on also this just saved me a few hours. thanks
    – Mac A.
    Jan 28, 2020 at 18:44
3

I had a similar problem & I solved it by adding this method to my payment-method model:

/**
 * Get config payment action, do nothing if status is pending
 *
 * @return string|null
 */
public function getConfigPaymentAction()
{
    return ($this->getConfigData('order_status') == 'pending')? null : parent::getConfigPaymentAction();
}

Taken from \Magento\Payment\Model\Method\Free

0

Your store->order status pending and processing State Code And Title is something like this.

enter image description here

1
  • It is same as in the above screenshot.
    – D.T
    Dec 13, 2016 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.