Skip to content

Commit

Permalink
Fix for media queries (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
em411 authored Aug 4, 2021
1 parent b49cb9c commit e4de01c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/Repository/MediaRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,25 @@ public function findOneEnabledByCode(string $code, string $localeCode): ?MediaIn
;
}

public function findBySectionCode(string $sectionCode, ?string $localeCode): array
public function findBySectionCode(string $sectionCode, string $localeCode, string $channelCode): array
{
return $this->createQueryBuilder('o')
->innerJoin('o.channels', 'channel')
->leftJoin('o.translations', 'translation')
->innerJoin('o.sections', 'section')
->where('translation.locale = :localeCode')
->innerJoin('o.channels', 'channels')
->andWhere('translation.locale = :localeCode')
->andWhere('section.code = :sectionCode')
->andWhere('o.enabled = true')
->andWhere('channels.code = :channelCode')
->setParameter('localeCode', $localeCode)
->setParameter('sectionCode', $sectionCode)
->setParameter('channelCode', $channelCode)
->getQuery()
->getResult()
;
;
}

public function findByProductCode(string $productCode, string $channelCode, ?string $localeCode): array
public function findByProductCode(string $productCode, string $localeCode, string $channelCode): array
{
return $this->createQueryBuilder('o')
->leftJoin('o.translations', 'translation')
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/MediaRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function createListQueryBuilder(string $locale): QueryBuilder;

public function findOneEnabledByCode(string $code, string $localeCode): ?MediaInterface;

public function findBySectionCode(string $sectionCode, ?string $localeCode): array;
public function findBySectionCode(string $sectionCode, string $localeCode, string $channelCode): array;

public function findByProductCode(string $productCode, string $channelCode, ?string $localeCode): array;
public function findByProductCode(string $productCode, string $localeCode, string $channelCode): array;
}
4 changes: 3 additions & 1 deletion src/Resources/config/routing/shop/media.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bitbag_sylius_cms_plugin_shop_media_render_template:
method: findOneEnabledByCode
arguments:
- $code
- "expr:service('sylius.context.channel').getChannel().getCode()"
- "expr:service('sylius.context.locale').getLocaleCode()"

bitbag_sylius_cms_plugin_shop_media_download:
path: /media/download/{code}
Expand All @@ -42,6 +42,7 @@ bitbag_sylius_cms_plugin_shop_media_index_by_section_code:
method: findBySectionCode
arguments:
- $sectionCode
- "expr:service('sylius.context.locale').getLocaleCode()"
- "expr:service('sylius.context.channel').getChannel().getCode()"

bitbag_sylius_cms_plugin_shop_media_index_by_product_code:
Expand All @@ -55,4 +56,5 @@ bitbag_sylius_cms_plugin_shop_media_index_by_product_code:
method: findByProductCode
arguments:
- $productCode
- "expr:service('sylius.context.locale').getLocaleCode()"
- "expr:service('sylius.context.channel').getChannel().getCode()"

0 comments on commit e4de01c

Please sign in to comment.