Magento Asked on November 17, 2021
I’ve created a new offline payment module using this generator http://cedcommerce.com/magento-2-module-creator/payment-module
config.xml
....
<order_status>pending_payment</order_status>
....
system.xml
<field id="order_status" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
<label>New Order Status</label><source_model>PackageNameModuleNameModelConfigSourceOrderStatusPendingpayment</source_model>
</field>
I’want to set new order status to pending
or pending_payment
, but it set to processing when creating a order every time.
first create observer into events.xml appcodeAdamsmageStatuschangeetcevents.xml
<?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="AdamsmageStatuschangeObserverOrderObserver" />
</event>
</config>
second create Observer file at following location appcodeAdamsmageStatuschangeObserverOrderObserver.php
<?php
namespace AdamsmageStatuschangeObserver;
use MagentoFrameworkEventObserverInterface;
class OrderObserver implements ObserverInterface
{
public function execute(MagentoFrameworkEventObserver $observer)
{
$order = $observer->getEvent()->getOrder();
// also if you want to check condition here like only offline payment method than order status update etc....
$order->setState("pending")->setStatus("pending");
$order->save();
}
Answered by Anas Mansuri on November 17, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP