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.

    create the event.xml on your module under the Vendor/Module/etc/event.xml and add the below code

    <?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="checkout_submit_all_after">
            <observer name="checkout_order_place_after" instance="VendorModuleObserverPlaceAfter" />
        </event>
    </config>

    create the PlaceAfter.php on your module under the Vendor/Module/Observer/PlaceAfter.php and add the below code

    <?php
    
    namespace VendorModuleObserver;
    
    use MagentoFrameworkEventObserverInterface;
    use MagentoFrameworkEventObserver as EventObserver;
    use PsrLogLoggerInterface;
    use MagentoSalesApiOrderRepositoryInterface;
    
    
    class PlaceAfter implements ObserverInterface
    {
    
        protected $_customerSession;
        /**
         * @var OrderRepositoryInterface
         */
        protected $orderRepository;
        /**
         * @var LoggerInterface
         */
        protected $logger;
        /**
         * @var MagentoSalesModelOrderFactory
         */
        protected $orderModel;
        /**
         * @var MagentoSalesModelOrderEmailSenderOrderSender
         */
        protected $orderSender;
    
        /**
         * @param MagentoSalesModelOrderFactory $orderModel
         * @param MagentoSalesModelOrderEmailSenderOrderSender $orderSender
         * @param MagentoCheckoutModelSession $checkoutSession
         *
         * @codeCoverageIgnore
         */
        public function __construct(
            MagentoSalesModelOrderFactory $orderModel,
            LoggerInterface $logger,
            MagentoSalesModelOrderEmailSenderOrderSender $orderSender,
            MagentoCustomerModelSession $customerSession,
            OrderRepositoryInterface $orderRepository,
            MagentoSalesApiDataOrderInterface $orderData
        )
        {
            $this->logger = $logger;
            $this->orderModel = $orderModel;
            $this->orderSender = $orderSender;
            $this->_customerSession = $customerSession;
            $this->orderRepository = $orderRepository;
            $this->orderData = $orderData;
        }
    
        /**
         * @param MagentoFrameworkEventObserver $observer
         * @return void
         */
        public function execute(MagentoFrameworkEventObserver $observer)
        {
            $order = $observer->getEvent()->getOrder();
            $orderId = $order->getEntityId();
            $this->logger->info(print_r($orderId,true));
            $guestemail = "test@gmail.com";
            
            $comment = sprintf(
                __("%s customer order converted to : %s guest user"),
                $order->getCustomerEmail(),$guestemail
            );
            $order->addStatusHistoryComment($comment);
            $order->setCustomerId(null);
            $order->setCustomerIsGuest(1);
            $order->setCustomerEmail($guestemail);
            $this->orderRepository->save($order);
    
            $order->setCanSendNewEmailFlag(true);
            $order->save();
            $this->_customerSession->setForceOrderMailSentOnSuccess(true);
            $this->orderSender->send($order);
            
            return $this;
        }
    }

     

    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