How to implement your business logic using the event system

The PIM uses the Symfony event system and fires events when something happens inside the system. For you, this means that you can create your own services that interact with those objects whenever certain action happens within the PIM.


We highly recommend you to implement your business code on listeners, this way you will not depends on Akeneo or Pim interfaces, you will keep your code easily testable and you will not fear backward compatibility break anymore.

For more details about event listeners, you can read the Symfony documentation


In the following example we will assume you want to be emailed about each product modification. In order to do that you can create an event listener that will send the email.

# /src/Acme/Bundle/AppBundle/EventSubscriber/ProductModificationListener.php

namespace Acme\Bundle\AppBundle\EventListener;

use Symfony\Component\EventDispatcher\GenericEvent;
use Pim\Bundle\CatalogBundle\Model\ProductInterface;

class ProductModificationListener
    private $mailer;

    public function __construct(\Swift_Mailer $mailer)
        $this->mailer = $mailer;

    public function onPostSave(GenericEvent $event)
        $subject = $event->getSubject();

        if (!$subject instanceof ProductInterface) {
            // don't do anything if it's not a product

        $message = \Swift_Message::newInstance()
            ->setSubject('A product modification event have been fired')


And there is the service definition

  • YAML
    # app/config/services.yml
            class: Acme\Bundle\AppBundle\EventListener\ProductModificationListener
                - '@swiftmailer.mailer'
                - { name: kernel.event_listener, event:, method: onPostSave }
  • XML
    <!-- app/config/services.xml -->
    <service id="my.listener" class="Acme\Bundle\AppBundle\EventListener\ProductModificationListener">
        <tag name="kernel.event_listener" event="" method="onPostSave" />
  • PHP
    // app/config/services.php
        ->register('my.listener', 'Acme\Bundle\AppBundle\EventListener\ProductModificationListener')
        ->addTag('kernel.event_listener', array('event' => '', 'method' => 'onPostSave'))