Extend and override default functionality

The Pacemaker import functionality is desigend to work standalone. But, up from version 3.8, it is possible to use the Magento code directory <magento-install-dir>/app/code/ as well to extend the Pacemaker import functionality, without the need to deploy it as composer library.

Override existing classes

In some cases, it’ll 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.

To do so, a minimum Magento module has to be created. 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 corresponing observer can extend the class that has to be overwritten, or may completely implement the custom business logic. Assuming that the the original class will be extended, this can look like

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 the same way. If functionality has to be extended, it’ll also be necessary to add the configuration for the workflow engine. The worklow engine configuration can either be done be 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 then.

Everything else will NOT be different that 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 has to be registered in the workflow engine’s configuration. To do so, 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"
            ]
        }
    ]
}