Skip to content

Commit

Permalink
Add ability to limit products and taxons when looking for name part
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed Jun 13, 2019
1 parent 901be26 commit 95d841e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 5 deletions.
Expand Up @@ -19,6 +19,7 @@ sylius_admin_ajax_product_by_name_phrase:
arguments:
phrase: $phrase
locale: expr:service('sylius.context.locale').getLocaleCode()
limit: 25

sylius_admin_ajax_product_by_code:
path: /code
Expand Down
Expand Up @@ -50,6 +50,8 @@ sylius_admin_ajax_taxon_by_name_phrase:
method: findByNamePart
arguments:
phrase: $phrase
locale: expr:service('sylius.context.locale').getLocaleCode()
limit: 25

sylius_admin_ajax_generate_taxon_slug:
path: /generate-slug/
Expand Down
Expand Up @@ -36,14 +36,14 @@ public function findByName(string $name, string $locale): array
/**
* {@inheritdoc}
*/
public function findByNamePart(string $phrase, string $locale): array
public function findByNamePart(string $phrase, string $locale, ?int $limit = null): array
{
return $this->createQueryBuilder('o')
->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
->andWhere('translation.name LIKE :name')
->setParameter('name', '%' . $phrase . '%')
->setParameter('locale', $locale)
->setMaxResults(25)
->setMaxResults($limit)
->getQuery()
->getResult()
;
Expand Down
Expand Up @@ -87,11 +87,12 @@ public function findRootNodes(): array
/**
* {@inheritdoc}
*/
public function findByNamePart(string $phrase, ?string $locale = null): array
public function findByNamePart(string $phrase, ?string $locale = null, ?int $limit = null): array
{
return $this->createTranslationBasedQueryBuilder($locale)
->andWhere('translation.name LIKE :name')
->setParameter('name', '%' . $phrase . '%')
->setMaxResults($limit)
->getQuery()
->getResult()
;
Expand Down
Expand Up @@ -26,5 +26,5 @@ public function findByName(string $name, string $locale): array;
/**
* @return array|ProductInterface[]
*/
public function findByNamePart(string $phrase, string $locale): array;
public function findByNamePart(string $phrase, string $locale, ?int $limit = null): array;
}
Expand Up @@ -39,7 +39,7 @@ public function findByName(string $name, string $locale): array;
/**
* @return array|TaxonInterface[]
*/
public function findByNamePart(string $phrase, ?string $locale = null): array;
public function findByNamePart(string $phrase, ?string $locale = null, ?int $limit = null): array;

public function createListQueryBuilder(): QueryBuilder;
}

0 comments on commit 95d841e

Please sign in to comment.