How to extend

Order workflow

Add custom export format

Create an own module:
  • As the first step, we need to introduce a custom module

  • See how to create a new Module at the Magento developer documentation

Add custom notification handler

First, you have to declare the handler in the di.xml

app/code/MyModule/Custom/etc/di.xml
<type name="TechDivision\OrderUpdateNotificationDispatcherApi\Api\NotificationHandlerInterface">
    <arguments>
        <argument name="handlers" xsi:type="array">
            <item name="order.update.custom" xsi:type="object">MyModule\CustomHandler\Model\CustomHandler</item>
        </argument>
    </arguments>
</type>

Then, you have to create the handler class and implement the TechDivision\OrderUpdateNotificationDispatcherApi\Api\NotificationHandlerInterface

There you have to configure your pipeline.

Check the given notification type first, because all collected notifications will be forwarded to each registered class.

app/code/MyModule/Custom/Model/CustomHandler.php
public function execute(NotificationInterface $notification): HandlerResultInterface
{
    // Check if this notification is relevant for this handler
    if (!($notification->getDocument() instanceof CustomInterface)) {
        $this->logger->debug('CustomHandler received an irrelevant notification');
        return $this->handlerResultFactory->create();
    }

    $pipelineInitData = $this->initializationDataFactory->create();
    $pipelineInitData->setPipelineConfiguration(
        [
            'name' => 'order_update',
            'description' => 'some testing pipeline',
            'use-working-directory' => false,
            'conditions' => [],
            'steps' => [
                [
                    'name' => 'custom_creation',
                    'executorType' => CustomCreatorExecutor::class,
                    'sortOrder' => 30,
                    'description' => 'custom msg',
                    'conditions' => [
                        PreviousStepsFinished::class,
                        self::COND_ATTEMPTS_LIMIT_5
                    ],
                        'arguments' => [
                        'notification_identifier' => $notification->getUniqueIdentifier(),
                        'external_order_id' => $notification->getDocument()->getExternalOrderId()
                    ],
                ],
            ]
        ]
    );
    $pipelineInitData->setArguments([]);

    return $this->handlerResultFactory->create(
        [
            'data' => [$pipelineInitData],
            'isHandled' => true
        ]
    );
}

The move files step will be added automatically.

After that, you need to implement your custom executor.

Add custom file system observer

First, you have to declare the file pattern and reader provider in the di.xml for openTRANS and/or json format.

app/code/MyModule/Custom/etc/di.xml
<type name="TechDivision\OrderUpdateFileSystemObserver\Model\FilePatternProvider">
    <arguments>
        <argument name="configuration" xsi:type="array">
            <item name="custom" xsi:type="array">
                <item name="disabled" xsi:type="boolean">false</item>
                <item name="pattern_instance" xsi:type="object">MyModule\Custom\Virtual\CustomFilePattern</item>
            </item>
            <item name="customxml" xsi:type="array">
                <item name="disabled" xsi:type="boolean">false</item>
                <item name="pattern_instance" xsi:type="object">MyModule\Custom\Virtual\CustomXmlFilePattern</item>
            </item>
        </argument>
    </arguments>
</type>

<virtualType name="MyModule\Custom\Virtual\CustomFilePattern" type="TechDivision\OrderUpdateFileSystemObserver\Model\BaseFilePattern">
    <arguments>
        <argument name="globPattern" xsi:type="string">your_pattern*.json</argument>
        <argument name="importPath" xsi:type="string">var/pacemaker/import</argument>
    </arguments>
</virtualType>
<virtualType name="MyModule\Custom\Virtual\CustomXmlFilePattern" type="TechDivision\OrderUpdateFileSystemObserver\Model\BaseFilePattern">
    <arguments>
        <argument name="globPattern" xsi:type="string">your_pattern*.xml</argument>
        <argument name="importPath" xsi:type="string">var/pacemaker/import</argument>
    </arguments>
</virtualType>

Next you have to implement the file reader provider for json and/or openTRANS format. Also you can determine your resolver chain fo the openTRANS standard. Here you can do your needed operations.

app/code/MyModule/Custom/etc/di.xml
<type name="TechDivision\OrderUpdateFileSystemObserver\Model\FileReaderProvider">
    <arguments>
        <argument name="configuration" xsi:type="array">
            <item name="custom" xsi:type="array">
                <item name="disabled" xsi:type="boolean">false</item>
                <item name="pattern_key" xsi:type="string">custom</item>
                <item name="reader_instance" xsi:type="object">MyModule\Custom\Model\CustomFileReader</item>
            </item>
            <item name="customxml" xsi:type="array">
                <item name="disabled" xsi:type="boolean">false</item>
                <item name="pattern_key" xsi:type="string">customxml</item>
                <item name="reader_instance" xsi:type="object">MyModule\Custom\Virtual\CustomXmlFileReader</item>
            </item>
        </argument>
    </arguments>
</type>

<type name="MyModule\Custom\Model\CustomFileReader">
    <arguments>
        <argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Json</argument>
    </arguments>
</type>
<virtualType name="MyModule\Custom\Virtual\CustomXmlFileReader" type="MyModule\Custom\Model\CustomFileReader">
    <arguments>
        <argument name="customResolver" xsi:type="object">MyModule\Custom\Model\Resolver\Virtual\CustomResolverChain</argument>
        <argument name="serializer" xsi:type="object">TechDivision\OrderUpdateNotificationDispatcherApi\Model\Serializer\XmlSerialize</argument>
    </arguments>
</virtualType>

<virtualType name="MyModule\Custom\Model\Resolver\Virtual\CustomResolverChain" type="MyModule\Custom\Model\Resolver\CustomResolverChain">
    <arguments>
        <argument name="customResolvers" xsi:type="array">
            <item name="default" xsi:type="object">MyModule\Custom\Model\Resolver\Xml\CustomDefaultXmlResolver</item>
            <item name="items" xsi:type="object">MyModule\Custom\Model\Resolver\Xml\CustomItemXmlResolver</item>
            ...
            <item name="comments" xsi:type="object">MyModule\Custom\Model\Resolver\Xml\CustomCommentXmlResolver</item>
            <item name="cleanup" xsi:type="object">MyModule\Custom\Model\Resolver\Xml\CustomCleanUp</item>
        </argument>
    </arguments>
</virtualType>

For implementations of the needed classes, check for example the techdivision/order-update-file-system-observer-invoice module