-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from matesich/master
TEAMS-920 - Added missing process of category_uid filter input
- Loading branch information
Showing
3 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/Model/Resolver/Products/Query/CategoryUidArgsProcessor.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,66 @@ | ||
<?php | ||
/** | ||
* ScandiPWA_CatalogGraphQl | ||
* | ||
* @category ScandiPWA | ||
* @package ScandiPWA_CatalogGraphQl | ||
* @author <[email protected]> | ||
* @copyright Copyright (c) 2018 Scandiweb, Ltd (https://scandiweb.com) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace ScandiPWA\CatalogGraphQl\Model\Resolver\Products\Query; | ||
|
||
use Magento\Framework\GraphQl\Query\Uid; | ||
use Magento\Framework\GraphQl\Query\Resolver\ArgumentsProcessorInterface; | ||
|
||
/** | ||
* Category UID processor class for category uid and category id arguments | ||
*/ | ||
class CategoryUidArgsProcessor implements ArgumentsProcessorInterface | ||
{ | ||
protected const ID = 'category_id'; | ||
protected const UID = 'category_uid'; | ||
|
||
protected Uid $uidEncoder; | ||
|
||
/** | ||
* @param Uid $uidEncoder | ||
*/ | ||
public function __construct(Uid $uidEncoder) | ||
{ | ||
$this->uidEncoder = $uidEncoder; | ||
} | ||
|
||
/** | ||
* Override to enable both category_id and category_uid to be used at the same time | ||
* | ||
* @param string $fieldName | ||
* @param array $args | ||
* @return array | ||
* @throws GraphQlInputException | ||
*/ | ||
public function process( | ||
string $fieldName, | ||
array $args | ||
): array { | ||
$idFilter = $args['filter'][self::ID] ?? []; | ||
$uidFilter = $args['filter'][self::UID] ?? []; | ||
|
||
if (empty($uidFilter)) { | ||
return $args; | ||
} | ||
|
||
if (isset($uidFilter['eq'])) { | ||
$args['filter'][self::ID]['eq'] = $this->uidEncoder->decode((string) $uidFilter['eq']); | ||
} elseif (!empty($uidFilter['in'])) { | ||
foreach ($uidFilter['in'] as $uid) { | ||
$args['filter'][self::ID]['in'][] = $this->uidEncoder->decode((string) $uid); | ||
} | ||
|
||
unset($args['filter'][self::ID]['eq']); | ||
} | ||
|
||
unset($args['filter'][self::UID]); | ||
} | ||
} |
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