I need to create a CSV file on every order I receive. How can I do this? Can you guys please suggest me a way to do this or an existing module that does that?


  • Do you want to sync order data to another system? – Khoa TruongDinh Dec 12 '19 at 3:32
  • No. I just need to automatically create a CSV from the last order. This file needs to be uploaded to the server – Gerardo Siano Dec 12 '19 at 4:07
  • you can use sales_order_place_after observer and get required data in CSV – Pawan Dec 12 '19 at 4:14
  • Uhm, can you please tell me more about it? – Gerardo Siano Dec 12 '19 at 4:18
  • please see my answer, I just get order data. you can put CSV logic based on your requirement. – Pawan Dec 12 '19 at 5:07

You need to create a small module, which will use event-observer feature of magento. we will put an observer which will get trigger when any order will get placed!

create following files:




<?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="Pawan_GenerateCSV" setup_version="1.0.0">


<?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'>



namespace Pawan\GenerateCSV\Observer;

use Magento\Framework\Event\ObserverInterface;

class GenerateCSV implements ObserverInterface
 protected $_objectManager;
 private $logger;
 private $productFactory;

  public function __construct(
    \Magento\Framework\ObjectManagerInterface $objectManager,
    \Psr\Log\LoggerInterface $logger,
    \Magento\Catalog\Model\ProductFactory $productFactory
  ) {
      $this->_objectManager = $objectManager;
      $this->logger = $logger;
      $this->productFactory = $productFactory;

  public function execute(\Magento\Framework\Event\Observer $observer)
    $order = $observer->getEvent()->getOrder();
    $order_id = $order->getIncrementId();
    $this->logger->info("observer working");  


Explanation: Now you have all Order data in observer class, form here you can get order, product information and can get data in CSV

Hope above will help!

| improve this answer | |

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.