/** * @return PropertyWriter */ private function createPropertyWriterAdapter() { return PropertyWriter::createFromGlobalSingleton(); }
/** * @param array $records * @throws \Exception */ private function performImport($records) { $articleWriter = new ArticleWriter(); $pricesWriter = new PriceWriter(); $categoryWriter = new CategoryWriter(); $configuratorWriter = ConfiguratorWriter::createFromGlobalSingleton(); $translationWriter = new TranslationWriter(); $propertyWriter = PropertyWriter::createFromGlobalSingleton(); $relationWriter = new RelationWriter($this); $imageWriter = new ImageWriter($this); $defaultValues = $this->getDefaultValues(); foreach ($records['article'] as $index => $article) { try { $this->modelManager->getConnection()->beginTransaction(); $articleWriterResult = $articleWriter->write($article, $defaultValues); $processedFlag = isset($article['processed']) && $article['processed'] == 1; /** * Only processed data will be imported */ if (!$processedFlag) { $pricesWriter->write($articleWriterResult->getArticleId(), $articleWriterResult->getDetailId(), array_filter($records['price'], function ($price) use($index) { return $price['parentIndexElement'] == $index; })); $categoryWriter->write($articleWriterResult->getArticleId(), array_filter($records['category'], function ($category) use($index) { return $category['parentIndexElement'] == $index && ($category['categoryId'] || $category['categoryPath']); })); $configuratorWriter->writeOrUpdateConfiguratorSet($articleWriterResult, array_filter($records['configurator'], function ($configurator) use($index) { return $configurator['parentIndexElement'] == $index; })); $propertyWriter->writeUpdateCreatePropertyGroupsFilterAndValues($articleWriterResult->getArticleId(), $article['orderNumber'], $this->filterPropertyValues($records, $index, $articleWriterResult)); $translationWriter->write($articleWriterResult->getArticleId(), $articleWriterResult->getDetailId(), $articleWriterResult->getMainDetailId(), array_filter($records['translation'], function ($translation) use($index) { return $translation['parentIndexElement'] == $index; })); } /** * Processed and unprocessed data will be imported */ if ($processedFlag) { $article['mainNumber'] = $article['orderNumber']; } $relationWriter->write($articleWriterResult->getArticleId(), $article['mainNumber'], array_filter($records['accessory'], function ($accessory) use($index, $articleWriterResult) { return $accessory['parentIndexElement'] == $index && $articleWriterResult->getMainDetailId() == $articleWriterResult->getDetailId(); }), 'accessory', $processedFlag); $relationWriter->write($articleWriterResult->getArticleId(), $article['mainNumber'], array_filter($records['similar'], function ($similar) use($index, $articleWriterResult) { return $similar['parentIndexElement'] == $index && $articleWriterResult->getMainDetailId() == $articleWriterResult->getDetailId(); }), 'similar', $processedFlag); $imageWriter->write($articleWriterResult->getArticleId(), $article['mainNumber'], array_filter($records['image'], function ($image) use($index) { return $image['parentIndexElement'] == $index; })); $this->modelManager->getConnection()->commit(); } catch (AdapterException $e) { $this->modelManager->getConnection()->rollBack(); $message = $e->getMessage(); $this->saveMessage($message); } } }