2

I have an external service that i want to use it in some parts of magento 2.4 checkout page. I can do it well, so, my problem is: I can not get data after pressing submit order, because magento generates order number after redirecting from payment page. So my question is that, how can I get order number on order place? my external service, holds some data of product but if I don't have order id I can not get those datas.

3
  • Which payment method?
    – Sohel Rana
    Jul 9, 2021 at 14:42
  • @SohelRana any payment, custom payment
    – MGPM
    Jul 10, 2021 at 11:30
  • Use checkout_submit_all_after for all payment methods and for paypal use paypal_express_place_order_success event. Both events are fire after order place.
    – Sohel Rana
    Jul 10, 2021 at 14:19

1 Answer 1

2

You can event checkout_onepage_controller_success_action this will help you to get all the data related to the order

<?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_onepage_controller_success_action">
    <observer name="vendor_module_observer_frontend_checkout_onepagecontrollersuccessaction_checkout_onepage_controller_success_action" instance="Vendor\Module\Observer\Frontend\Checkout\OnepageControllerSuccessAction"/>
</event>
</config>

And create observer for the same

<?php
 declare(strict_types=1);

 namespace Vendor\Module\Observer\Frontend\Checkout;

 class OnepageControllerSuccessAction implements 
 \Magento\Framework\Event\ObserverInterface
 {

     /**
      * Execute observer
      *
      * @param \Magento\Framework\Event\Observer $observer
      * @return void
      */
      public function execute(
      \Magento\Framework\Event\Observer $observer
       ) {
        //Your observer code
         }
     }
2
  • Thanks for your responce, I need Incremental_id before success, before redirecting
    – MGPM
    Jul 10, 2021 at 11:29
  • $order = $observer->getEvent()->getOrder(); $incrementId = $order->getIncrementId();
    – Asssd
    Jul 10, 2021 at 18:25

Your Answer

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

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