Events

There are a couple of events which you can use to modify the exported data or to modify the imported order objects.

  • pimcore.dataobject.postCsvItemExport
  • Pimcore\Bundle\DataHubFileExportBundle\Event\IsValidExportItemEvent
  • Pimcore\Bundle\DataHubProductsupBundle\Event\DeliveryModifyResultEvent
  • Pimcore\Bundle\DataHubProductsupBundle\Event\OrderItemPreSaveEvent
  • Pimcore\Bundle\DataHubProductsupBundle\Event\OrderPreSaveEvent

Sample implementation

Sample configuration for EventListener
    AppBundle\EventListener\DataHubProductsupListener:
        tags:
            - { name: kernel.event_listener, event: pimcore.dataobject.postCsvItemExport, method: postCsvItemExport }
            - { name: kernel.event_listener, event: Pimcore\Bundle\DataHubFileExportBundle\Event\IsValidExportItemEvent, method: isValidExportItem }
            - { name: kernel.event_listener, event: Pimcore\Bundle\DataHubProductsupBundle\Event\DeliveryModifyResultEvent, method: modifyResult }
            - { name: kernel.event_listener, event: Pimcore\Bundle\DataHubProductsupBundle\Event\OrderItemPreSaveEvent, method: preOrderItemSave }
            - { name: kernel.event_listener, event: Pimcore\Bundle\DataHubProductsupBundle\Event\OrderPreSaveEvent, method: orderPreSave }
The appropriate EventListener would look like this
<?php
namespace AppBundle\EventListener;

use Pimcore\Bundle\DataHubProductsupBundle\Event\DeliveryModifyResultEvent;
use Pimcore\Bundle\DataHubProductsupBundle\Event\OrderItemPreSaveEvent;
use Pimcore\Bundle\DataHubProductsupBundle\Event\OrderPreSaveEvent;
use Pimcore\Bundle\DataHubFileExportBundle\Event\IsValidExportItemEvent;


class DataHubProductsupListener
{

    public static function postCsvItemExport(\Pimcore\Event\Model\DataObjectEvent $event)
    {

        $object = $event->getObject();
        if ($object instanceof \Pimcore\Model\DataObject\Car) {
            $context = $event->getArgument('context');
            if ($context['source'] == 'pimcore_data_hub_file_export') {
                $objectData = $event->getArgument('objectData');
                /**
                 * @var $exporter \Pimcore\Bundle\DataHubFileExportBundle\Exporter\AbstractExporter
                 */
                $exporter = $context['exporter'];
                $dataHubConfig = $exporter->getDataHubConfiguration();
                if ($dataHubConfig->getName() == 'products-up') {
                    $objectData['name'] = $objectData['name'] . ' - Modified by event';
                    $event->setArgument('objectData', $objectData);
                }
            } elseif ($context['source'] == 'pimcore-export') {
                //pimcore grid export
                $objectData = $event->getArgument('objectData');
                $objectData['fullpath'] .= '- Modified....';

                $event->setArgument('objectData', $objectData);
            }

        }
    }

    public static function isValidExportItem(IsValidExportItemEvent  $event)
    {
        /**
         * @var $exporter \Pimcore\Bundle\DataHubProductsupBundle\Exporter\Productsup
         */
        $exporter = $event->getExporter();
        $object = $event->getObject();

        if ($object->getId() == 81) {
            $event->setIsValid(false);
        }
    }


    public static function modifyResult(DeliveryModifyResultEvent $event)
    {
        /**
         * @var $dataHubConfig \Pimcore\Bundle\DataHubBundle\Configuration
         * @var $list \Pimcore\Bundle\DataHubProductsupBundle\Model\CacheItem\Listing
         */
        $dataHubConfig = $event->getConfiguration();
        $list = $event->getList();

        $data = $event->getData();
        foreach ((array)$data as $k => $entry) {
            $entry['price'] = 123.90;
            $data[$k] = $entry;
        }
        $event->setData($data);
    }

    public static function preOrderItemSave(OrderItemPreSaveEvent $event)
    {

        $object = $event->getOrder();

        if ($object instanceof \Pimcore\Model\DataObject\OnlineShopOrder) {

            $orderItem = $event->getOrderItem();
            $payload = $event->getPayload();
            $data = $event->getData();
            $config = $event->getConfiguration();

            $orderItem->setProduct(\Pimcore\Model\DataObject::getById(82));
        }
    }

    public static function orderPreSave(OrderPreSaveEvent $event)
    {

        $order = $event->getOrder();

        if ($order instanceof \Pimcore\Model\DataObject\OnlineShopOrder) {

            $payload = $event->getPayload();
            $config = $event->getConfiguration();

            $order->setKey('test23-' . time());
        }
    }

}