0

I need to generate a Json file containing information about Order just right after a customer finish his checkout and the order is generated in admin using orderId
This json file will contain data about products shipping methods ... related to this order.
if you can help

4
  • can you describe it in more details? Jul 23, 2021 at 10:30
  • Can you recheck please? ask me if it is not clear for you.
    – Jad
    Jul 23, 2021 at 10:33
  • How customer confirm the order into your system? Jul 23, 2021 at 10:35
  • Once A customer did his checkout and the the order is created in admin
    – Jad
    Jul 23, 2021 at 11:05

1 Answer 1

0

You need to do following things :

  1. create the events.xml file on following location.

app\code\Vendor\Extension\etc\events.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="Vendor\Extensoin\Observer\OrderObserver" />
      </event>
</config>
  1. Now create OrderObserver.php on following location.

app\code\Vendor\Extension\Observer\OrderObserver.php

<?php
namespace Vendor\Extension\Observer;
 
use Magento\Framework\Event\ObserverInterface;
 
class OrderObserver implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $Orderdata = $observer->getEvent()->getOrder();

        //Write your logic to create Json file withh the Order information
    }
}
9
  • how can I test if it's working please
    – Jad
    Jul 23, 2021 at 11:56
  • Implement the code into extension and check it. Jul 23, 2021 at 12:22
  • Yes I created an extension, where can I check if it's working please?
    – Jad
    Jul 23, 2021 at 12:31
  • You can put the log and check that is working or not. and have you read the answer that you need to put the json file logic there into the observer file. Jul 23, 2021 at 12:35
  • Do you have just an idea how to get customer data for exple address into json in OrderObserver.php?Thank you
    – Jad
    Jul 23, 2021 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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