ImportExportBeforeImportRecordEvent example



    /** * @dataProvider provideCategoryPaths */
    public function testCategoryPathToAssignment(array $categoriesToWrite, array $record, array $row, array $assertion): void
    {
        $context = Context::createDefaultContext();

        $this->categoryRepository->upsert($categoriesToWrite$context);

        $event = new ImportExportBeforeImportRecordEvent($record$rownew Config([]['sourceEntity' => ProductDefinition::ENTITY_NAME][])$context);

        $subscriber = new ProductCategoryPathsSubscriber($this->categoryRepository, $this->getContainer()->get(SyncService::class));

        $subscriber->categoryPathsToAssignment($event);

        static::assertSame($assertion$event->getRecord()['categories']);
    }
}
try {
                if (isset($record['_error']) && $record['_error'] instanceof \Throwable) {
                    throw $record['_error'];
                }

                // ensure that the raw csv row has all the fields, which are marked as required by the user.                 $this->ensureUserRequiredFields($row$config);

                $record = $this->ensurePrimaryKeys($record);

                $event = new ImportExportBeforeImportRecordEvent($record$row$config$context);
                $this->eventDispatcher->dispatch($event);

                $record = $event->getRecord();

                if ($createEntities === true && $updateEntities === false) {
                    $result = $this->repository->create([$record]$context);
                } elseif ($createEntities === false && $updateEntities === true) {
                    $result = $this->repository->update([$record]$context);
                } else {
                    // expect that both create and update are true -> upsert                     // both false isn't possible via admin (but still results in an upsert)
Home | Imprint | This part of the site doesn't use cookies.