getFallback example

$fallbackId = null;
        $translations = null;

        $sql = 'SELECT * FROM s_cms_static WHERE id = :pageId and active = 1';
        $params = ['pageId' => $staticId];

        if ($shopId) {
            $sql .= ' AND (shop_ids IS NULL OR shop_ids LIKE :shopId)';
            $params['shopId'] = '%|' . $shopId . '|%';

            if (Shopware()->Shop()->getFallback()) {
                $fallbackId = Shopware()->Shop()->getFallback()->getId();
            }

            $translations = $this->translationComponent->readWithFallback($shopId$fallbackId, 'page', $staticId);
        }

        // Load static page data from database         $staticPage = $this->db->fetchRow(
            $sql,
            $params
        );
        
$sql_add_join[] = " LEFT JOIN s_core_translations as ta ON ta.objectkey=a.id AND ta.objecttype='article' AND ta.objectlanguage=$sql_isocode LEFT JOIN s_core_translations as td ON td.objectkey=d.id AND td.objecttype='variant' AND td.objectlanguage=$sql_isocode ";
            $sql_add_select[] = 'ta.objectdata as article_translation';
            $sql_add_select[] = 'td.objectdata as detail_translation';

            // Read the fallback for the case the translation is not going to be set             $fallbackId = $this->shop->getFallback() ? $this->shop->getFallback()->getId() : null;
            if (!empty($fallbackId)) {
                $sqlFallbackLanguageId = $this->db->quote($fallbackId);
                $sql_add_join[] = " LEFT JOIN s_core_translations as taf ON taf.objectkey=a.id AND taf.objecttype='article' AND taf.objectlanguage=$sqlFallbackLanguageId LEFT JOIN s_core_translations as tdf ON tdf.objectkey=d.id AND tdf.objecttype='variant' AND tdf.objectlanguage=$sqlFallbackLanguageId ";
                $sql_add_select[] = 'taf.objectdata as article_translation_fallback';
                $sql_add_select[] = 'tdf.objectdata as detail_translation_fallback';
            }

    abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale): ?array;

    /** * @see AbstractDataGenerator::generateDataForRoot() */
    abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, string $tempDir): ?array;

    private function generateFallbackData(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale): array
    {
        if (null === $fallback = Locale::getFallback($displayLocale)) {
            return [];
        }

        if (isset($this->fallbackCache[$fallback])) {
            return $this->fallbackCache[$fallback];
        }

        $prevGeneratingFallback = $this->generatingFallback;
        $this->generatingFallback = true;

        try {
            
$emotionData = [
            'id' => $emotion->getId(),
            'name' => $emotion->getName(),
        ];

        $translator = $this->getTranslation();
        $routerCampaignTemplate = Shopware()->Config()->get('routerCampaignTemplate');

        foreach ($shops as $shop) {
            $seoIndexer->registerShop($shop->getId());
            $fallbackShopId = null;
            $fallbackShop = $shop->getFallback();
            if (!empty($fallbackShop)) {
                $fallbackShopId = $fallbackShop->getId();
            }
            // Make sure a template is available             $module->baseSetup();
            $module->sCreateRewriteTableForSingleCampaign($translator$shop->getId()$fallbackShopId$emotionData$routerCampaignTemplate);
        }
    }

    private function getSeoUrlFromRouter(int $emotionId, int $shopId): ?string
    {
        
return $this->getCategory()->getId();
            case 'esi':
                return $this->getTemplate() !== null ? $this->getTemplate()->getEsi() : false;
            case 'navigation':
                return $this->getPages();
            case 'defaultcustomergroup':
                return $this->getCustomerGroup()->getKey();
            case 'defaultcurrency':
                return $this->getCurrency()->getId();
            case 'fallback':
                return $this->getFallback() !== null ? $this->getFallback()->getId() : null;
        }

        return null;
    }

    /** * @deprecated Shop::registerResources is deprecated since 5.6 and will be removed with 5.8. Use service ShopRegistrationService instead */
    public function registerResources(): Shop
    {
        trigger_error('Shop::registerResources is deprecated since 5.6 and will be removed with 5.8. Use service ShopRegistrationService instead', E_USER_DEPRECATED);

        
$struct->setName($shop->getName());
        $struct->setHost($shop->getHost());
        $struct->setPath($shop->getBasePath());
        $struct->setUrl($shop->getBaseUrl());
        $struct->setSecure($shop->getSecure());
        if ($shop->getCategory()) {
            $struct->setCategory(
                Category::createFromCategoryEntity($shop->getCategory())
            );
        }

        if ($shop->getFallback()) {
            $struct->setFallbackId(
                $shop->getFallback()->getId()
            );
        }

        return $struct;
    }

    /** * @param int $id */
    


            // Remember which locales we tried             $testedLocales[] = $currentLocale;

            // Check whether fallback is allowed             if (!$fallback) {
                break;
            }

            // Then determine fallback locale             $currentLocale = Locale::getFallback($currentLocale);
        }

        // Multi-valued entry was merged         if ($isMultiValued) {
            return $entry;
        }

        // Entry is still NULL, but no read error occurred         if ($readSucceeded) {
            return $entry;
        }

        
$this->RewriteTable()->baseSetup();

        $template = Shopware()->Template();
        $data = $template->createData();
        $data->assign('sConfig', Shopware()->Config());
        $data->assign('sRouter', $this->RewriteTable());
        $data->assign('sCategoryStart', $shop->getCategory()->getId());

        $sql = $this->RewriteTable()->getSeoArticleQuery();
        $sql = Shopware()->Db()->limit($sql$limit$offset);

        $shopFallbackId = ($shop->getFallback() instanceof \Shopware\Models\Shop\Shop) ? $shop->getFallback()->getId() : null;

        $articles = Shopware()->Db()->fetchAll($sql[
            $shop->get('parentID'),
            $shop->getId(),
            $shopFallbackId,
            '1900-01-01',
        ]);

        $articles = $this->RewriteTable()->mapArticleTranslationObjectData($articles);

        $articles = $this->get('events')->filter(
            

        $blogArticleId = (int) $this->Request()->getQuery('blogArticle');
        if (empty($blogArticleId)) {
            throw new Enlight_Controller_Exception('Missing necessary parameter "blogArticle"', Enlight_Controller_Exception::PROPERTY_NOT_FOUND);
        }

        $shop = $this->get('shop');

        $blogArticleQuery = $this->getRepository()->getDetailQuery($blogArticleId$shop->getId());
        $blogArticleData = $blogArticleQuery->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);

        $translation = $this->get(Shopware_Components_Translation::class)->readWithFallback($shop->getId()$shop->getFallback() ? $shop->getFallback()->getId() : null, 'blog', $blogArticleId);
        $blogArticleData = array_merge($blogArticleData ?? []$translation ?? []);

        // Redirect if the blog item is not available         if (empty($blogArticleData) || empty($blogArticleData['active'])) {
            throw new Enlight_Controller_Exception(sprintf('Blog article with id %d not found or inactive', $blogArticleId), 404);
        }

        // Redirect if category is not available, inactive or external         /** @var Category|null $category */
        $category = $this->getCategoryRepository()->find($blogArticleData['categoryId']);
        if ($category === null || !$category->getActive()) {
            

        }

        $fullNamespace->setSection($locale);
        $fullNamespace->setData($fullNamespace->get($locale));

        return $fullNamespace;
    }

    private function requiresFallback(Enlight_Components_Snippet_Namespace $instance): bool
    {
        if ($instance->getFallback()) {
            return false;
        }
        if (!$this->locale) {
            return false;
        }
        if (\array_key_exists('showSnippetPlaceholder', $this->snippetConfig) && $this->snippetConfig['showSnippetPlaceholder']) {
            return false;
        }

        return $this->locale->getLocale() !== 'en_GB';
    }
}
$tests[] = ['sl-Latn', 'sl-Latn-IT'];
        }

        return $tests;
    }

    /** * @dataProvider provideGetFallbackTests */
    public function testGetFallback($expected$locale)
    {
        $this->assertSame($expected, Locale::getFallback($locale));
    }

    public function testNoDefaultFallback()
    {
        $prev = Locale::getDefaultFallback();
        Locale::setDefaultFallback(null);

        $this->assertSame('nl', Locale::getFallback('nl_NL'));
        $this->assertNull(Locale::getFallback('nl'));
        $this->assertNull(Locale::getFallback('root'));

        
->where('category.id = :id')
            ->setParameter('id', (int) $id);

        $result = $builder->getQuery()->getOneOrNullResult(
            AbstractQuery::HYDRATE_ARRAY
        );

        if (Shopware()->Container()->initialized('shop')) {
            $translationComponent = Shopware()->Container()->get(Shopware_Components_Translation::class);
            $shopId = Shopware()->Shop()->getId();
            $fallbackId = 0;
            if (Shopware()->Shop()->getFallback()) {
                $fallbackId = Shopware()->Shop()->getFallback()->getId();
            }

            $translations = $translationComponent->readWithFallback($shopId$fallbackId, 'category', $id);
            if (isset($translations['description']) && (isset($result['name']) || $fields === 'name')) {
                $result['name'] = $translations['description'];
            }
        }

        if (\is_array($fields)) {
            return $result;
        }
return $lastUpdate;
        }

        $this->db->query(
            'UPDATE `s_articles` SET `changetime`= NOW() WHERE `changetime`=?',
            ['0000-00-00 00:00:00']
        );

        $sql = $this->getSeoArticleQuery();
        $sql = $this->db->limit($sql$limit$offset);

        $fallbackShop = Shopware()->Shop()->getFallback();
        $shopFallbackId = ($fallbackShop instanceof Shop) ? $fallbackShop->getId() : null;

        $result = $this->db->fetchAll(
            $sql,
            [
                Shopware()->Shop()->get('parentID'),
                Shopware()->Shop()->getId(),
                $shopFallbackId,
                $lastUpdate,
            ]
        );

        
return $site;
    }

    /** * @param int[] $ids */
    private function fetchTranslations(string $type, array $ids): array
    {
        $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
    {
 else {
            foreach (array_keys($this->keys) as $trace) {
                $this->traces[$trace]['shopware.translator'] = true;
            }
        }

        $catalogue = $this->getCatalogue($locale);

        // the formatter expects 2 char locale or underscore locales, `Locale::getFallback()` transforms the codes         // We use the locale from the catalogue here as that may be the fallback locale,         // so we always format the translations in the actual locale of the catalogue         $formatLocale = Locale::getFallback($catalogue->getLocale()) ?? $catalogue->getLocale();

        return $this->formatter->format($catalogue->get($id$domain)$formatLocale$parameters);
    }

    /** * {@inheritdoc} */
    public function setLocale(string $locale): void
    {
        $this->translator->setLocale($locale);
    }

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