We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Step 1: First you need to add registration.php file in the following path: app/code/Magemonkey/Orderstatus/

    Add below code in it.

    <?php
    MagentoFrameworkComponentComponentRegistrar::register(
    	MagentoFrameworkComponentComponentRegistrar::MODULE,
    	'Magemonkey_Orderstatus',
    	__DIR__
    );

    Step 2: Next, you need to add module.xml file in the following path:
    app/code/Magemonkey/Orderstatus/etc/

    Add below code in it.

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Magemonkey_Orderstatus" setup_version="1.0.0">
        </module>
    </config>

     

    Step 3: Now you need to add Orderstatus.php file in the following path: app/code/Magemonkey/Orderstatus/Cron/

    Add below code in it.

    <?php
    
    namespace MagemonkeyOrderstatusCron;
    
    class Orderstatus
    {
    	protected $_logger;
    	protected $_orderCollectionFactory;
    	protected $orderObj;
    	protected $timezoneInterface;
       	
       	public function __construct(
           PsrLogLoggerInterface $logger,
           MagentoSalesModelResourceModelOrderCollectionFactory $orderCollectionFactory,
           MagentoSalesModelOrder $orderObj,
           MagentoFrameworkStdlibDateTimeTimezoneInterface $timezoneInterface
       	) 
        {
         	$this->_logger = $logger;
         	$this->_orderCollectionFactory = $orderCollectionFactory;
         	$this->_orderObj = $orderObj;
         	$this->_timezoneInterface = $timezoneInterface;
        }
    
    	public function execute()
    	{
    		$paymentMethod = 'stripe_payments_sofort';
    		/* get order collection */
    		$collection = $this->_orderCollectionFactory->create()->addFieldToSelect('*')
    		->addFieldToFilter('status', ['in' => 'pending']);
    
    	     /* join with payment table */
    	    $collection->getSelect()
    	    ->join(
    	        ["sop" => "sales_order_payment"],
    	        'main_table.entity_id = sop.parent_id',
    	        array('method')
    	    )
    	    ->where('sop.method = ?',$paymentMethod);
    
    	    /* get current date time */
    	    $current_datetime = $this->_timezoneInterface->date()->format('Y-m-d H:i:s');
    	    
    	    /* set default time in second */
    		$set_default_time = 3600;
    	    foreach ($collection->getData() as $key => $orders) {
    	    	
    	    	$created_at = $orders['created_at'];
    			$dateTimeZone_order = $this->_timezoneInterface->date(new DateTime($created_at))->format('Y-m-d H:i:s');
    
    			/* get time diff from order datetime and current datetime */
    			$time_diff = strtotime($current_datetime) - strtotime($dateTimeZone_order);
    
    			/* change order status to processing */
    			if($set_default_time <= $time_diff){
    				/* @var $order MagentoSalesModelOrder */
    				$order = $this->_orderObj->load($orders['entity_id']);
    			    $order->setStatus("processing");
    			    $order->save();
    			}
    	    }
    	}
    }

     

     

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote