Important

You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Security Support ends in January 2023. Read version 5.0 (the latest LTS version) of the Oro documentation to get the updated information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Postponing Rows

When the data from one row in the import file depends on the data in another row (for example, a subsidiary Customer that has another headquarters Customer as a parent), it is critical to process the parent row first and proceed with importing the dependent row afterward. You can analyze the import file and track this kind of dependencies. You can postpone processing the row that precedes the data it depends on by adding the following logics in the Strategy or Strategy Event.

Postponing in Strategy

Example of usage:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
 class CustomAddOrReplaceStrategy extends ConfigurableAddOrReplaceStrategy
 {
         /**
          * {@inheritdoc}
          */
         protected function beforeProcessEntity($entity)
         {
             $entity = parent::beforeProcessEntity($entity);

             if ($this->shouldBePostponed($entity)) {
                 $this->context->addPostponedRow($this->context->getValue('rawItemData'));

                 return null;
             }

             return $entity;
         }

         // Rest of your code here
         // ...
 }

Postponing in Strategy Event

Example of usage:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
 class CustomerTaxCodeImportExportSubscriber implements EventSubscriberInterface
 {
     /**
      * {@inheritdoc}
      */
     public static function getSubscribedEvents()
     {
         return [
             StrategyEvent::PROCESS_AFTER => ['afterImportStrategy', -255],
         ];
     }

     public function afterImportStrategy(StrategyEvent $event)
     {
         $event->getContext()->addPostponedRow(
             $event->getContext()->getValue('rawItemData')
         );
     }
 }