Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DQL] Change hardcoded enabled value to parameter in where statements #12720

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/cookbook/shop/embedding-products.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ Your extending repository class should look like that:
{
return $this->createQueryBuilder('o')
->innerJoin('o.channels', 'channel')
->andWhere('o.enabled = true')
->andWhere('o.enabled = :enabled')
->andWhere('channel = :channel')
->innerJoin('o.productTaxons', 'productTaxons')
->addOrderBy('productTaxons.position', 'asc')
->innerJoin('productTaxons.taxon', 'taxon')
->andWhere('taxon.code = :code')
->setParameter('code', $code)
->setParameter('channel', $channel)
->setParameter('enabled', true)
->setMaxResults($count)
->getQuery()
->getResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public function createListQueryBuilder(string $locale): QueryBuilder
public function findEnabledForChannel(ChannelInterface $channel): array
{
return $this->createQueryBuilder('o')
->andWhere('o.enabled = true')
->andWhere('o.enabled = :enabled')
->andWhere(':channel MEMBER OF o.channels')
->setParameter('channel', $channel)
->setParameter('enabled', true)
->addOrderBy('o.position')
->getQuery()
->getResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ public function createShopListQueryBuilder(

$queryBuilder
->andWhere(':channel MEMBER OF o.channels')
->andWhere('o.enabled = true')
->andWhere('o.enabled = :enabled')
->setParameter('locale', $locale)
->setParameter('channel', $channel)
->setParameter('enabled', true)
;

// Grid hack, we do not need to join these if we don't sort by price
Expand Down Expand Up @@ -128,10 +129,11 @@ public function findLatestByChannel(ChannelInterface $channel, string $locale, i
->addSelect('translation')
->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
->andWhere(':channel MEMBER OF o.channels')
->andWhere('o.enabled = true')
->andWhere('o.enabled = :enabled')
->addOrderBy('o.createdAt', 'DESC')
->setParameter('channel', $channel)
->setParameter('locale', $locale)
->setParameter('enabled', true)
->setMaxResults($count)
->getQuery()
->getResult()
Expand All @@ -145,10 +147,11 @@ public function findOneByChannelAndSlug(ChannelInterface $channel, string $local
->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
->andWhere('translation.slug = :slug')
->andWhere(':channel MEMBER OF o.channels')
->andWhere('o.enabled = true')
->andWhere('o.enabled = :enabled')
->setParameter('channel', $channel)
->setParameter('locale', $locale)
->setParameter('slug', $slug)
->setParameter('enabled', true)
->getQuery()
->getOneOrNullResult()
;
Expand All @@ -171,9 +174,10 @@ public function findOneByChannelAndCode(ChannelInterface $channel, string $code)
$product = $this->createQueryBuilder('o')
->where('o.code = :code')
->andWhere(':channel MEMBER OF o.channels')
->andWhere('o.enabled = true')
->andWhere('o.enabled = :enabled')
->setParameter('channel', $channel)
->setParameter('code', $code)
->setParameter('enabled', true)
->getQuery()
->getOneOrNullResult()
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ public function findEnabledForZonesAndChannel(array $zones, ChannelInterface $ch
protected function createEnabledForChannelQueryBuilder(ChannelInterface $channel): QueryBuilder
{
return $this->createQueryBuilder('o')
->andWhere('o.enabled = true')
->andWhere('o.enabled = :enabled')
->andWhere('o.archivedAt IS NULL')
->andWhere(':channel MEMBER OF o.channels')
->setParameter('channel', $channel)
->setParameter('enabled', true)
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public function findChildrenByChannelMenuTaxon(?TaxonInterface $menuTaxon = null
->addSelect('child')
->innerJoin('o.parent', 'parent')
->leftJoin('o.children', 'child')
->andWhere('o.enabled = true')
->andWhere('o.enabled = :enabled')
->andWhere('parent.code = :parentCode')
->addOrderBy('o.position')
->setParameter('parentCode', ($menuTaxon !== null) ? $menuTaxon->getCode() : 'category')
->setParameter('enabled', true)
->getQuery()
->getResult()
;
Expand All @@ -54,11 +55,12 @@ public function findOneBySlug(string $slug, string $locale): ?TaxonInterface
return $this->createQueryBuilder('o')
->addSelect('translation')
->innerJoin('o.translations', 'translation')
->andWhere('o.enabled = true')
->andWhere('o.enabled = :enabled')
->andWhere('translation.slug = :slug')
->andWhere('translation.locale = :locale')
->setParameter('slug', $slug)
->setParameter('locale', $locale)
->setParameter('enabled', true)
->getQuery()
->getOneOrNullResult()
;
Expand Down