From 32e4206ca5370a7cef21f4fdad4cd58cbd5882f2 Mon Sep 17 00:00:00 2001 From: Patryk Date: Fri, 16 Mar 2018 17:05:15 +0100 Subject: [PATCH] Do not rely on admin's locale for section autocomplete --- src/Repository/SectionRepository.php | 25 ++++++++++++++++--- .../config/routing/admin/section.yml | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Repository/SectionRepository.php b/src/Repository/SectionRepository.php index d421ae29..9ac91f5a 100755 --- a/src/Repository/SectionRepository.php +++ b/src/Repository/SectionRepository.php @@ -32,13 +32,32 @@ public function createListQueryBuilder(): QueryBuilder */ public function findByNamePart(string $phrase, ?string $locale = null): array { - return $this->createQueryBuilder('o') - ->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale') + return $this->createTranslationBasedQueryBuilder($locale) ->andWhere('translation.name LIKE :name') ->setParameter('name', '%' . $phrase . '%') - ->setParameter('locale', $locale) ->getQuery() ->getResult() ; } + + /** + * @param $locale + * + * @return QueryBuilder + */ + private function createTranslationBasedQueryBuilder($locale): QueryBuilder + { + $queryBuilder = $this->createQueryBuilder('o') + ->leftJoin('o.translations', 'translation') + ; + + if (null !== $locale) { + $queryBuilder + ->andWhere('translation.locale = :locale') + ->setParameter('locale', $locale) + ; + } + + return $queryBuilder; + } } diff --git a/src/Resources/config/routing/admin/section.yml b/src/Resources/config/routing/admin/section.yml index 7b2c329f..3fa37667 100755 --- a/src/Resources/config/routing/admin/section.yml +++ b/src/Resources/config/routing/admin/section.yml @@ -30,7 +30,7 @@ bitbag_sylius_cms_plugin_admin_ajax_section_by_name_phrase: method: findByNamePart arguments: phrase: $phrase - locale: expr:service('sylius.context.locale').getLocaleCode() + locale: null bitbag_sylius_cms_plugin_admin_ajax_section_by_code: path: /ajax/sections/code