Important

You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date 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 class CustomAddOrReplaceStrategy extends ConfigurableAddOrReplaceStrategy
 2 {
 3         /**
 4          * {@inheritdoc}
 5          */
 6         protected function beforeProcessEntity($entity)
 7         {
 8             $entity = parent::beforeProcessEntity($entity);
 9
10             if ($this->shouldBePostponed($entity)) {
11                 $this->context->addPostponedRow($this->context->getValue('rawItemData'));
12
13                 return null;
14             }
15
16             return $entity;
17         }
18
19         // Rest of your code here
20         // ...
21 }

Postponing in Strategy Event

Example of usage:

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