Add custom export format

Create an own module

First of all, we need to introduce a custom module.

Please refer to Create a New Module in Magento’s developer documentation.

In this example, we name the module MyModule_CustomOrderExportFormat.

mkdir -p app/code/MyModule/CustomOrderExportFormat/etc
touch app/code/MyModule/CustomOrderExportFormat/etc/module.xml
touch app/code/MyModule/CustomOrderExportFormat/registration.php
app/code/MyModule/CustomOrderExportFormat/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'MyModule_CustomOrderExportFormat',
    __DIR__
);
app/code/MyModule/CustomOrderExportFormat/etc/module.xml
<?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="MyModule_CustomOrderExportFormat" setup_version="1.0.0">
        <sequence>
            <module name="TechDivision_PacemakerOrderExport"/>
        </sequence>
    </module>
</config>

We need to specify TechDivision_PacemakerOrderExport module in the sequence of our new module.xml to be able to overwrite the existing pipeline configuration.

Create your format executor

Now we need to create our own executor, which will load the order and generate the target format for our export.

Therefore we create a class as follows.

app/code/MyModule/CustomOrderExportFormat/Model/MyExecutor.php
<?php
declare(strict_types=1);

namespace MyModule\CustomOrderExportFormat\Model;

use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\OrderRepositoryInterface;
use TechDivision\ProcessPipelines\Api\ExecutorLoggerInterface;
use TechDivision\ProcessPipelines\Api\StepInterface;
use TechDivision\ProcessPipelines\Model\Executor\AbstractExecutor;

class MyExecutor extends AbstractExecutor
{
    /**
     * @var OrderRepositoryInterface
     */
    private $orderRepository;

    /**
     * @param ExecutorLoggerInterface $logger
     * @param OrderRepositoryInterface $orderRepository
     */
    public function __construct(
        ExecutorLoggerInterface $logger,
        OrderRepositoryInterface $orderRepository
    ) {
        parent::__construct($logger);
        $this->orderRepository = $orderRepository;
    }

    /**
     * @param StepInterface $step
     * @return void
     * @throws LocalizedException
     */
    public function process(StepInterface $step)
    {
        // Load the order with the order_id given in step arguments
        $order = $this->orderRepository->get((int)$step->getArgumentValueByKey('order_id'));

        // Formatting logic here...
    }
}

If you want to use the default transport adapter to move the result to a location within the system, you need to persist the body within the current working directory in the file order-export.body. Please refer to example module for more details.

Register the executor and dropdown select

Finally, it would be helpful if you would include your executor in the format list. That will automatically add your formatter to he dropdown in Store  Configuration  Pacemaker  Order Workflow.

app/code/MyModule/CustomOrderExportFormat/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="TechDivision\PacemakerOrderExport\Model\ExportFormatProvider">
        <arguments>
            <argument name="formatList" xsi:type="array">
                <item name="my_custom_format" xsi:type="array">
                    <item name="code" xsi:type="string">my_custom_format</item>
                    <item name="label" xsi:type="string">My Custom Format</item>
                    <item name="type" xsi:type="string">MyModule\CustomOrderExportFormat\Model\MyExecutor</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

Examples

Checkout following resource for an example module.