How to Create a New Connector

Like your catalog, your data sources, channels and business rules are unique.

This is why a common task is to work on connectors to import and export the PIM data as expected.

Akeneo PIM comes with a set of configurable connectors based on re-usable classes and services.

Main Concepts

A connector can be packaged as a Symfony bundle.

It contains jobs such as imports and exports.

Each job is composed of steps, by default, each step contains a reader, a processor and a writer.

These elements provide their expected configuration to be used.

For instance, to import a CSV file as products, the reader reads each line, the processor transforms them into products, and the writer then saves the products.

Create our Connector

Here, we’ll create a new simple connector which uses existing services.

Create a new bundle:

1
2
3
4
5
6
7
8
9
<?php

namespace Acme\Bundle\DemoConnectorBundle;

use Akeneo\Bundle\BatchBundle\Connector\Connector;

class AcmeDemoConnectorBundle extends Connector
{
}

Register the bundle in AppKernel:

1
2
3
4
5
6
public function registerBundles()
{
    // ...
        new Acme\Bundle\DemoConnectorBundle\AcmeDemoConnectorBundle(),
    // ...
}

Configure our Job

Configure a job in Resources/config/batch_jobs.yml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
connector:
    name: Demo Connector
    jobs:
        demo_product_export:
            title: pim_base_connector.jobs.demo_product_export.title
            type:  export
            steps:
                export:
                    title: pim_base_connector.jobs.demo_product_export.export.title
                    services:
                        reader:    pim_base_connector.reader.doctrine.product
                        processor: pim_base_connector.processor.product_to_flat_array
                        writer:    pim_base_connector.writer.file.csv_product

Here we use some existing readers, processors and writers from native csv product export, they are defined as services in config files of the PimBaseConnectorBundle, we’ll see later how to create your own elements.

Title keys can be translated in messages.en.yml

1
2
3
4
5
6
pim_base_connector:
    jobs:
        demo_product_export:
            title: Product Export CSV
            export:
                title: Product Export Step

Use our new Connector

Now if you refresh cache, your new export can be found under Spread > Export profiles > Create export profile.

You can run the job from UI or you can use following command:

php app/console akeneo:batch:job my_job_code

Create our Specific Connector

In the previous section, the main concepts behind connectors were explained. We have created a new connector which uses existing parts, until we were able to reproduce the native CSV product export features but on a different connector.

Now, let’s code a specific connector How to Create a Specific Connector