-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/Sylius/Bundle/ApiBundle/Filters/ExchangeRateFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ApiBundle\Filters; | ||
|
||
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter; | ||
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface; | ||
use Doctrine\ORM\QueryBuilder; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class ExchangeRateFilter extends AbstractContextAwareFilter | ||
{ | ||
protected function filterProperty( | ||
string $property, | ||
$value, | ||
QueryBuilder $queryBuilder, | ||
QueryNameGeneratorInterface $queryNameGenerator, | ||
string $resourceClass, | ||
string $operationName = null | ||
) { | ||
if ($property === 'currencyCode') { | ||
$queryBuilder | ||
->innerJoin('o.sourceCurrency', 'sourceCurrency') | ||
->innerJoin('o.targetCurrency', 'targetCurrency') | ||
->where('sourceCurrency.code LIKE CONCAT(\'%\', :code, \'%\')') | ||
->orWhere('targetCurrency.code LIKE CONCAT(\'%\', :code, \'%\')') | ||
->setParameter('code', $value) | ||
; | ||
} | ||
} | ||
|
||
public function getDescription(string $resourceClass): array | ||
{ | ||
$description = []; | ||
|
||
$description['currencyCode'] = [ | ||
'type' => 'string', | ||
'required' => false, | ||
'property' => 'currencyCode', | ||
]; | ||
|
||
return $description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
This file is part of the Sylius package. | ||
(c) Paweł Jędrzejewski | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
--> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="sylius.api.filter.exchange_rate" class="Sylius\Bundle\ApiBundle\Filters\ExchangeRateFilter"> | ||
<tag name="api_platform.filter" id="exchange_rate_filter" /> | ||
<argument type="service" id="doctrine" /> | ||
</service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters