isFrontend() || !$entity->getId()) { return; } $storeId = (int)$this->storeManager->getStore()->getId(); if ($storeId <= 0) { return; } $isHomepage = $entity instanceof Homepage; $translations = $this->translationRepository->getTranslations( (int)$entity->getId(), $storeId, $isHomepage ? CmsTranslationRepository::ENTITY_WIKI_HOMEPAGE : CmsTranslationRepository::ENTITY_WIKI_CATEGORY, $isHomepage ? WikiFields::homepageCodes() : WikiFields::categoryCodes() ); $this->applyValues($entity, $translations); } /** @param Category[] $entities */ public function applyMany(array $entities, bool $homepage = false): void { if (!$this->isFrontend() || $entities === []) { return; } $storeId = (int)$this->storeManager->getStore()->getId(); if ($storeId <= 0) { return; } $entityIds = []; foreach ($entities as $entity) { if ($entity instanceof Category && $entity->getId()) { $entityIds[] = (int)$entity->getId(); } } $translations = $this->translationRepository->getTranslationsForEntities( $entityIds, $storeId, $homepage ? CmsTranslationRepository::ENTITY_WIKI_HOMEPAGE : CmsTranslationRepository::ENTITY_WIKI_CATEGORY, $homepage ? WikiFields::homepageCodes() : WikiFields::categoryCodes() ); foreach ($entities as $entity) { if ($entity instanceof Category && $entity->getId()) { $this->applyValues($entity, $translations[(int)$entity->getId()] ?? []); } } } private function applyValues(Category $entity, array $translations): void { foreach ($translations as $field => $value) { $entity->setData($field, $value); } } private function isFrontend(): bool { try { return $this->appState->getAreaCode() === 'frontend'; } catch (LocalizedException) { return false; } } }