/** * @return array */ public function getTranslationColumns() { $columns = ['article.id as articleId', 'variant.id as variantId', 'translation.objectlanguage as languageId', 'translation.name as name', 'translation.keywords as keywords', 'translation.metaTitle as metaTitle', 'translation.description as description', 'translation.description_long as descriptionLong', 'translation.additionalText as additionalText', 'translation.packUnit as packUnit']; if (!SwagVersionHelper::isDeprecated('5.3.0')) { $legacyAttributes = $this->getLegacyTranslationAttr(); if ($legacyAttributes) { foreach ($legacyAttributes as $attr) { $columns[] = $attr['name']; } } } $attributes = $this->getTranslatableAttributes(); if ($attributes) { foreach ($attributes as $attribute) { $columns[] = $attribute['columnName']; } } return $columns; }
/** * @return array */ public function getAllTranslationColumns() { if ($this->translationColumns === null) { $translationFields = ['name', 'additionalText', 'metaTitle', 'description', 'descriptionLong', 'keywords', 'packUnit']; $attributes = []; if (!SwagVersionHelper::isDeprecated('5.3.0')) { $attributes = array_map(function ($item) { return $item['name']; }, $this->getTranslationAttr()); } $this->translationColumns = array_merge($translationFields, $attributes); } return $this->translationColumns; }
/** * @param $records * @throws AdapterException * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\OptimisticLockException * @throws \Doctrine\ORM\TransactionRequiredException * @throws \Enlight_Event_Exception * @throws \Exception */ public function write($records) { if (empty($records['default'])) { $message = SnippetsHelper::getNamespace()->get('adapters/articlesTranslations/no_records', 'No article translation records were found.'); throw new \Exception($message); } $records = $this->eventManager->filter('Shopware_Components_SwagImportExport_DbAdapters_ArticlesTranslationsDbAdapter_Write', $records, ['subject' => $this]); $whiteList = ['name', 'description', 'descriptionLong', 'metaTitle', 'keywords']; $variantWhiteList = ['additionalText', 'packUnit']; $whiteList = array_merge($whiteList, $variantWhiteList); if (!SwagVersionHelper::isDeprecated('5.3.0')) { $elementBuilder = $this->getElementBuilder(); $legacyAttributes = $elementBuilder->getQuery()->getArrayResult(); if ($legacyAttributes) { foreach ($legacyAttributes as $attr) { $whiteList[] = $attr['name']; $variantWhiteList[] = $attr['name']; } } } $attributes = $this->getAttributes(); if ($attributes) { foreach ($attributes as $attribute) { $whiteList[] = $attribute['columnName']; $variantWhiteList[] = $attribute['columnName']; } } $articleDetailRepository = $this->manager->getRepository(Detail::class); $shopRepository = $this->manager->getRepository(Shop::class); foreach ($records['default'] as $index => $record) { try { $record = $this->validator->filterEmptyString($record); $this->validator->checkRequiredFields($record); $this->validator->validate($record, ArticleTranslationValidator::$mapper); $shop = false; if (isset($record['languageId'])) { $shop = $shopRepository->find($record['languageId']); } if (!$shop) { $message = SnippetsHelper::getNamespace()->get('adapters/articlesTranslations/lang_id_not_found', 'Language with id %s does not exists for article %s'); throw new AdapterException(sprintf($message, $record['languageId'], $record['articleNumber'])); } $articleDetail = $articleDetailRepository->findOneBy(['number' => $record['articleNumber']]); if (!$articleDetail) { $message = SnippetsHelper::getNamespace()->get('adapters/article_number_not_found', 'Article with order number %s doen not exists'); throw new AdapterException(sprintf($message, $record['articleNumber'])); } $articleId = $articleDetail->getArticle()->getId(); if ($articleDetail->getKind() === 1) { $data = array_intersect_key($record, array_flip($whiteList)); $type = 'article'; $objectKey = $articleId; } else { $data = array_intersect_key($record, array_flip($variantWhiteList)); $type = 'variant'; $objectKey = $articleDetail->getId(); } if (!empty($data)) { $data = $this->prepareAttributePrefix($data, $attributes); $this->translationComponent->write($shop->getId(), $type, $objectKey, $data); } } catch (AdapterException $e) { $message = $e->getMessage(); $this->saveMessage($message); } } }