How to extend

The Pacemaker import functionality is designed to work standalone.

Up from version 3.8.0, it is possible to use the Magento code directory <magento-install-dir>/app/code/ to extend the Pacemaker import functionality without the need to deploy it as a composer library.

Override existing classes

In some cases, it will be necessary to override a default class of the Pacemaker import library.

For example, if additional attributes have been added to a non-EAV entity or the import should keep going if a website that has been referenced in the CSV file is not available in the Magento instance.

For that purpose, a minimum Magento module has to be created.

  1. In general, in every project that uses Pacemaker the module will be named Import, e.g. MyProject\Import.

At this point, the directory structure should look like

<magento-install-dir>/
└--app/
   └--code/
      └--MyProject/
         └--Import/
            |--registration.php
            └--etc/
               └--di.xml
               └--config.xml
               └--module.xml
               └--adminhtml/
                  └--system.xml

As the Pacemaker import functionality is completely based on Symfony, at least a DI configuration, that enables us to override the default class must be available.

The configuration file must be located in the directory <magento-install-dir>/app/code/MyProject/Import/symfony/Resources/config/services.xml.

<magento-install-dir>/
└--app/
   └--code/
      └--MyProject/
         └--Import/
            |--registration.php
            |--etc/
            |  └--di.xml
            |  └--config.xml
            |  └--module.xml
            |  └--adminhtml/
            |     └--system.xml
            |--Observers/
            |  └--ProductWebsiteObserver.php
            └--symfony/
               └--Resources/
                  └--config/
                     └--services.xml

The simple DI configuration that we used to override the original observer will have the following content:

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <services>
        <service
            id="import_product.observer.product.website"
            class="MyProject\Import\Product\Observers\ProductWebsiteObserver"/>
    </services>
</container>

The corresponding observer can extend the class that has to be overwritten, or may completely implement the custom business logic.

Given that the original class is extended, this could look as the following code:

namespace MyProject\Import\Product\Observers;

/**
 * Observer that creates/updates the product's website relations.
 */
class ProductWebsiteObserver extends \TechDivision\Import\Product\Observers\ProductWebsiteObserver
{

    /**
     * Process the observer's business logic.
     *
     * @return array The processed row
     */
    protected function process()
    {
        // custom code here
    }
}

Add custom functionality

Custom functionality can be added in the same way.

If the feature has to be extended, it will also be necessary to add the workflow engine’s configuration.

The workflow engine configuration can either be accomplished be snippets located in the global configuration directory under <magento-install-dir>/app/etc/configuration or in the configuration directory of the module, which will be app/code/MyProject/Import/etc.

Everything else will not be different than writing an extension that will be deployed in the Magento vendor directory.

Register the module

Finally, to make the module available for usage in the Pacemaker import functionality, it must be registered in the workflow engine’s configuration.

For this purpose, add a snippet <magento-install-dir>/app/code/configuration/additional-vendor-dirs.json which has the following content:

{
    "additional-vendor-dirs": [
        {
            "vendor-dir": "app/code",
            "libraries": [
                "MyProject/Import"
            ]
        }
    ]
}