Hyvä Theme is Now Open Source: What This Means for Magento Community - Mageplaza
Hyvä is now Open Source and free. Discover what changed, what remains commercial, how it impacts the Magento ecosystem, and how to maximize its full potential.
Efficient order management keeps your Magento 2 store running smoothly and ensures accurate transaction data. Exporting and importing orders streamlines your workflow, improves analysis, and optimizes overall performance.
If you’re working with product data, this guide on exporting products in Magento 2 offers practical steps to export full or filtered product data using CSV format.
This guide covers the best practices for importing and exporting orders in Magento 2, helping you gain insights into customer behavior, optimize processes, and elevate the overall shopping experience.
Key Takeaways
In Magento 2, store admins can import and export data using various formats. CSV and XML:
Common purposes for order import/export:
Exporting orders in Magento 2 is essential for maintaining transaction records, performing analysis, and streamlining order management. Here are three effective methods to export orders from your Magento 2 store:
#1. Login to the Magento 2 Admin Panel and navigate to the Sale > Orders

#2. On the Orders page, you’ll see a list of all store orders. Each row represents an individual order, with columns showing details, including:

#3. To select specific orders for export, click on the checkboxes next to the order IDs. If you want to export all orders, tick the checkbox in the header row to mark all visible orders.

#4. With the desired orders selected, click on the Export located above the orders list to expand the menu options.

#5. Select the file format (CSV or XML).

#6. Press on the Export button to begin the export process, and the resulting CSV file will contain your order data as seen in the default view.
To export orders programmatically using custom data in Magento 2, you need to follow these steps:
#1. Create file db_schema.xml in your module
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="sales_order_grid" resource="sales" comment="Sales Flat Order Grid">
<column xsi:type="varchar" name="coupon_code" nullable="true" length="255"/>
<column xsi:type="longtext" name="items" nullable="true"/>
<column xsi:type="varchar" name="shipping_region" nullable="true" length="255"/>
<column xsi:type="varchar" name="shipping_postcode" nullable="true" length="255"/>
<column xsi:type="varchar" name="shipping_city" nullable="true" length="255"/>
<column xsi:type="varchar" name="shipping_street" nullable="true" length="255"/>
<column xsi:type="varchar" name="shipping_fax" nullable="true" length="255"/>
<column xsi:type="varchar" name="shipping_telephone" nullable="true" length="255"/>
<column xsi:type="varchar" name="shipping_company" nullable="true" length="255"/>
<column xsi:type="varchar" name="shipping_country" nullable="true" length="255"/>
<column xsi:type="varchar" name="shipping_vat" nullable="true" length="255"/>
<column xsi:type="varchar" name="billing_region" nullable="true" length="255"/>
<column xsi:type="varchar" name="billing_postcode" nullable="true" length="255"/>
<column xsi:type="varchar" name="billing_city" nullable="true" length="255"/>
<column xsi:type="varchar" name="billing_street" nullable="true" length="255"/>
<column xsi:type="varchar" name="billing_fax" nullable="true" length="255"/>
<column xsi:type="varchar" name="billing_telephone" nullable="true" length="255"/>
<column xsi:type="varchar" name="billing_company" nullable="true" length="255"/>
<column xsi:type="varchar" name="billing_country" nullable="true" length="255"/>
<column xsi:type="varchar" name="billing_vat" nullable="true" length="255"/>
</table>
</schema>
#2. Create file di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Ui\Model\Export\ConvertToCsv" type="Mageplaza\BetterOrderGrid\Model\Export\ConvertToCsv"/>
</config>
#3. Create the Plugin:
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_BetterOrderGrid
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\BetterOrderGrid\Model\Export;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Ui\Model\Export\ConvertToCsv as UiConvertToCsv;
use Magento\Ui\Model\Export\MetadataProvider;
use Mageplaza\BetterOrderGrid\Helper\Data;
/**
* Class ConvertToCsv
*
* @package Mageplaza\BetterOrderGrid\Model\Export
*/
class ConvertToCsv extends UiConvertToCsv
{
/**
* @var Data
*/
protected $helperData;
/**
* ConvertToCsv constructor.
*
* @param Filesystem $filesystem
* @param Filter $filter
* @param MetadataProvider $metadataProvider
* @param Data $helperData
* @param int $pageSize
*
* @throws FileSystemException
*/
public function __construct(
Filesystem $filesystem,
Filter $filter,
MetadataProvider $metadataProvider,
Data $helperData,
$pageSize = 200
) {
$this->helperData = $helperData;
parent::__construct($filesystem, $filter, $metadataProvider, $pageSize);
}
/**
* Returns CSV file
*
* @return array
* @throws FileSystemException
* @throws LocalizedException
*/
public function getCsvFile()
{
$component = $this->filter->getComponent();
$name = hash('md5', microtime());
$file = 'export/' . $component->getName() . $name . '.csv';
$this->filter->prepareComponent($component);
$this->filter->applySelectionOnTargetProvider();
$dataProvider = $component->getContext()->getDataProvider();
$fields = $this->metadataProvider->getFields($component);
$options = $this->metadataProvider->getOptions();
$this->directory->create('export');
$stream = $this->directory->openFile($file, 'w+');
$stream->lock();
$stream->writeCsv($this->metadataProvider->getHeaders($component));
$i = 1;
$searchCriteria = $dataProvider->getSearchCriteria()
->setCurrentPage($i)
->setPageSize($this->pageSize);
$totalCount = (int) $dataProvider->getSearchResult()->getTotalCount();
while ($totalCount > 0) {
$items = $dataProvider->getSearchResult()->getItems();
foreach ($items as $item) {
if ($component->getName() === 'sales_order_grid' && $this->helperData->isEnabled()) {
$productArr = $this->helperData->convertOrderData($item->getEntityId());
$export_data = implode(' | ', $productArr);
$item->setProducts($export_data);
unset($productArr);
}
$this->metadataProvider->convertDate($item, $component->getName());
$stream->writeCsv($this->metadataProvider->getRowData($item, $fields, $options));
}
$searchCriteria->setCurrentPage(++$i);
$totalCount -= $this->pageSize;
}
$stream->unlock();
$stream->close();
return [
'type' => 'filename',
'value' => $file,
'rm' => true // can delete file after use
];
}
}
#4. Insert data into custom order columns.
Customize the code to insert data into your custom order columns as needed.
#5. Run setup upgrade
php bin/magento setup:upgrade
Then, click on the Export button again to generate the file.
First, start by downloading the Magento 2 Order Export extension by Mageplaza.
Step 1: General configuration

Step 2: Create a New Export Profile

Mageplaza > Order Export > Manage Export Profiles.Step 3: Select Export Format and Fields

Step 4: Configure Filters

Date range
Step 5: Set Export Delivery
Decide where the exported file should go:

Step 6: Save & Run

💡Tip:
For other advanced features such as log management & quick export, go to Mageplaza Order Export user guide to learn detailed steps.
First, you need to prepare order data for import:
entity_id (internal ID) and increment_id (order number) are unique to avoid conflicts.Here is the step-by-step guide to help you import orders successfully:
System and click Import


Validation Strategy to determine how the system handles errors during the import process:


Download Sample next to the Entity Type field to download a sample template.
Choose File button to choose the file for import.
Check Data to validate the file for any mistakes

During the import and export of orders, unexpected errors may occur. These errors can cause performance bottlenecks and operational delays. Below are some common issues and effective ways to tackle these challenges.
This typically occurs when the uploaded file does not meet Magento’s required format.
Solution: Make sure the file is in the correct CSV/XML format and follows Magento’s data schema. Refer to sample files provided by Magento or extensions for guidance.
Some mandatory fields (e.g., Order ID, Customer Email) are absent or incomplete.
Solution: Check the data file for missing columns or blank fields. Fill in the necessary information before re-importing.
Altering order files manually may break relationships between tables.
Solution: Always use validated files and proper import tools.
Default export uses UTC, causing discrepancies in local time.
Solution: Add a custom column or convert timestamps to your timezone.
Exported product counts may reflect filtered views, not totals.
Solution: Ignore filters and verify the complete export list.
The product SKUs in the order file do not exist in the Magento catalog.
Solution: Verify that all SKUs in the file match the products in Magento. Import missing products before reattempting to import the order.
The export process is complete, but no file is generated.
Solution: Check server logs for errors. Ensure the selected export entity contains data and that file permissions are correctly configured.
What formats can I use to export orders in Magento 2?
You can export orders in CSV (Comma-Separated Values) or XML (eXtensible Markup Language) formats.
What are the benefits of using Magento 2 Order Export extensions?
The Magento 2 Export Orders extensions provide several benefits for eCommerce businesses:
What should I do before importing orders?
Before importing, ensure your CSV file is in the correct format and click Check Data to validate it for any errors or inconsistencies.
Can I export orders by date range or order status?
Yes, you can apply filters such as date range or order status to export specific orders.
Can I clear import and export history manually or automatically?
Yes, you can clear import and export history manually or set it to clear automatically after a specified time.
What should I do to fix common errors when importing orders?
Common order import issues include incorrect data formatting, missing data fields, and extension-related conflicts. To fix these issues, you need to check error logs, review field mappings, and handle conflicts.
Can I use Magento 2 to export orders to third-party applications?
By using the Magento 2 Order Export extension from Mageplza, you can export orders to third-party applications. This tool integrates with external systems, making data sharing and management easy.
To sum up, importing and exporting orders in Magento 2 is a useful feature that helps businesses seamlessly manage order data, enhance productivity, and ensure smooth transactions. By following this guide and taking advantage of Magento 2’s powerful tool, you can manage the store’s data management effectively and keep your business running seamlessly.