Skip to content

Commit

Permalink
Merge pull request Sylius#123 from patrick477/master
Browse files Browse the repository at this point in the history
Do not rely on admin's locale for section autocomplete
  • Loading branch information
bitbager authored Mar 16, 2018
2 parents d957cb3 + 32e4206 commit 9437bff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions src/Repository/SectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/routing/admin/section.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9437bff

Please sign in to comment.