Extend and override default functionality

The Pacemaker import gets designed to work independently.

To extend the Pacemaker import without having to provide the Composer library, the Magento code directory <magento-install-dir>/app/code/ gets used from Pacemaker Import Community version 4.1.0.

Override existing classes

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

Use Cases:
  • additional attributes have been added to a non-EAV entity

  • the import should continue if a website URL referenced in the CSV file is unavailable in the Magento instance

Example

  • A minimal Magento module needs to get created

  • In any project that uses Pacemaker, the module is called Import

    • e.g. MyProject\Import

The directory structure should now look like this:
<PROJECT-ROOT>
    └── app
            └── code
                      └── MyProject
                              └── Import
                                        ├── registration.php
                                        └── etc
                                                └── di.xml
                                                └── config.xml
                                                └── module.xml
                                                └── adminhtml
                                                          └── system.xml

For the Symfony based Pacemaker import functionality, a DI configuration allows overriding the default class.

<PROJECT-ROOT>
    └── app
           └── code
                  └── MyProject
                         └── Import
                                ├── registration.php
                                ├── etc
                                │       └── di.xml
                                │       └── config.xml
                                │       └── module.xml
                                │       └── adminhtml
                                │               └── system.xml
                                ├── Observers
                                │       └── ProductWebsiteObserver.php
                                └── symfony
                                        └── Resources
                                                └── config
                                                        └── services.xml (1)
1 The configuration file services.xml must be located in the <magento-install-dir>/app/code/MyProject/Import/symfony/Resources/config/services.xml directory
The associated DI configuration file we use to override the original observer has 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"/> (1)
    </services>
</container>
1 Path to the required location used by Symfony
The required observer can extend the class to be overridden or fully implement its business logic. See the following example:
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 functions can get added in the same way described for Override existing classes

  • If the functionality needs to get extended, it is necessary to add the workflow engine configuration

  • The configuration of the workflow engine can be done either via snippets located in the global configuration directory

    • <magento-install-dir>/app/etc/configuration

    • or in the configuration directory of the module, which is as follows app/code/MyProject/Import/etc

Except for the modifications just made, everything else will get installed in the standard Magento Vendor directory.

Register the module

To make the module available in the Pacemaker importer, it must register in the workflow engine configuration.

Add the snippet <magento-install-dir>/app/code/configuration/additional-vendor-dirs.json with the following content to extend the existing configuration:
{
    "additional-vendor-dirs": [
        {
            "vendor-dir": "app/code",
            "libraries": [
                "MyProject/Import"
            ]
        }
    ]
}