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/ as well to extend the Pacemaker import functionality without the requirement 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.

  • A minimum Magento module has to be created.

  • In every project that uses the Pacemaker module, it will be named Import, e.g. MyProject\Import.

The directory structure should be simular to:

<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 entirely based on the Symfony Framework, as a bear minimum 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 we use to override the original observer requires 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.

If the initial class is extended, this could look similar to 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

A custom functionality can be added in the same way.

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

The workflow engine configuration can either be done by using snippets that are 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 is not different to writing an extension that will be deployed in the Magento vendor directory.

Register the module

To make the module available for usage in the Pacemaker import functionality, it must be registered in the workflow engine configuration.

To achieve this, add a snippet like <magento-install-dir>/app/etc/configuration/additional-vendor-dirs.json which has the following content:

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