readBatchWithFallback example



    protected function translateItems(array $items): array
    {
        try {
            $context = $this->contextService->getShopContext()->getShop();
        } catch (Exception $e) {
            return $items;
        }

        $ids = array_column($items, 'id');
        $translations = $this->translation->readBatchWithFallback($context->getId()$context->getFallbackId()$this->type->getTableName()$ids, false);

        if (empty($translations)) {
            return $items;
        }

        foreach ($items as &$item) {
            foreach ($translations as $translation) {
                if ($translation['objectkey'] === $item['id']) {
                    $item = array_merge($item$translation['objectdata']);
                }
            }
        }
return [];
        }

        $ids = array_column($blogArticles, 'id');
        $shop = $this->get('shop');
        $data = [];

        foreach ($blogArticles as $blogArticle) {
            $data[$blogArticle['id']] = $blogArticle;
        }

        $translations = $this->get(Shopware_Components_Translation::class)->readBatchWithFallback($shop->getId()$shop->getFallback() ? $shop->getFallback()->getId() : null, 'blog', $ids, false);

        foreach ($translations as $translation) {
            $data[$translation['objectkey']] = array_merge($data[$translation['objectkey']]$translation['objectdata']);
        }

        return $data;
    }

    private function getPerPage(Request $request, SessionInterface $session): int
    {
        if (!empty($request->attributes->get('sPerPage'))) {
            

    public function sGetCountryTranslation($country = [])
    {
        $languageId = $this->contextService->getShopContext()->getShop()->getId();
        $fallbackId = $this->contextService->getShopContext()->getShop()->getFallbackId();

        $translationData = $this->translationComponent
            ->readBatchWithFallback($languageId$fallbackId, 'config_countries');

        if (!$country) {
            return $translationData;
        }

        if (!isset($translationData[$country['id']])) {
            return $country;
        }

        // Pass (possible) translation to country         if ($translationData[$country['id']]['countryname']) {
            

    protected function readTranslationWithFallback($languageId$type)
    {
        $fallbackLanguageId = Shopware()->Db()->fetchOne(
            'SELECT fallback_id FROM s_core_shops WHERE id = ?',
            [$languageId]
        );

        return $this->translationComponent->readBatchWithFallback($languageId$fallbackLanguageId$type);
    }

    /** * Load template / document configuration (s_core_documents / s_core_documents_box) */
    protected function loadConfiguration4x()
    {
        $id = $this->_typID;

        $this->_document = new ArrayObject(
            Shopware()->Db()->fetchRow(
                

        $this->allExported = false;
    }

    /** * @param array<int> $ids * * @return array<array<string, string>> */
    private function fetchTranslations(array $ids, ShopContextInterface $shopContext): array
    {
        $data = $this->translation->readBatchWithFallback($shopContext->getShop()->getId()$shopContext->getShop()->getFallbackId(), 'blog', $ids, false);
        $translation = [];

        foreach ($data as $row) {
            $translation[$row['objectkey']] = $row['objectdata'];
        }

        return $translation;
    }
}
$shop = $this->container->get('shop');

        $shopId = $shop->getId();
        $fallbackShop = $shop->getFallback();

        $fallbackId = null;
        if ($fallbackShop !== null) {
            $fallbackId = $fallbackShop->getId();
        }

        return $this->container->get(Shopware_Components_Translation::class)
            ->readBatchWithFallback($shopId$fallbackId$type$ids, false);
    }

    private function fetchTranslation(int $objectKey, array $translations): array
    {
        foreach ($translations as $translation) {
            if ((int) $translation['objectkey'] === $objectKey) {
                return $translation['objectdata'];
            }
        }

        return [];
    }
$object[$objectIndex] = $fallback;
        }

        return $object;
    }

    /** * Loads all translations. */
    private function loadTranslations(): void
    {
        $this->translations = $this->translationService->readBatchWithFallback($this->language, $this->fallback, $this->type);
        $this->loaded = true;
    }

    /** * Determines if the translations have been loaded. */
    private function areTranslationsLoaded(): bool
    {
        return $this->loaded;
    }
}
if (\is_string($newKey)) {
                        $data[$newKey] = $value;
                    }
                }

                $form->getAttribute()->fromArray($data);
            }
        }

        $elementIds = array_keys($fields);

        $fieldTranslations = $this->get(Shopware_Components_Translation::class)->readBatchWithFallback(
            $context->getShop()->getId(),
            $context->getShop()->getFallbackId(),
            'forms_elements',
            $elementIds,
            false
        );

        foreach ($fieldTranslations as $fieldTranslation) {
            $key = $fieldTranslation['objectkey'];
            $translation = $fieldTranslation['objectdata'];

            
Home | Imprint | This part of the site doesn't use cookies.