-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LYNX-162: Add uids filters to entity queries custom_attriubtes fields (…
- Loading branch information
Showing
8 changed files
with
837 additions
and
388 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
app/code/Magento/CustomerGraphQl/Model/Resolver/CustomAttributeFilter.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,64 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CustomerGraphQl\Model\Resolver; | ||
|
||
use Magento\CustomerGraphQl\Model\Customer\ExtractCustomerData; | ||
use Magento\CustomerGraphQl\Model\Customer\GetCustomer; | ||
use Magento\Framework\Api\CustomAttributesDataInterface; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
/** | ||
* Resolver Custom Attribute filter | ||
*/ | ||
class CustomAttributeFilter implements ResolverInterface | ||
{ | ||
/** | ||
* @var GetCustomer | ||
*/ | ||
private GetCustomer $getCustomer; | ||
|
||
/** | ||
* @var ExtractCustomerData | ||
*/ | ||
private ExtractCustomerData $extractCustomerData; | ||
|
||
/** | ||
* @param GetCustomer $getCustomer | ||
* @param ExtractCustomerData $extractCustomerData | ||
*/ | ||
public function __construct( | ||
GetCustomer $getCustomer, | ||
ExtractCustomerData $extractCustomerData, | ||
) { | ||
$this->getCustomer = $getCustomer; | ||
$this->extractCustomerData = $extractCustomerData; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
): array { | ||
$customAttributes = $value[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES]; | ||
if (isset($args['uids']) && !empty($args['uids'])) { | ||
$selectedUids = array_values($args['uids']); | ||
return array_filter($customAttributes, function ($attr) use ($selectedUids) { | ||
return in_array($attr['uid'], $selectedUids); | ||
}); | ||
} | ||
|
||
return $customAttributes; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
app/code/Magento/CustomerGraphQl/Model/Resolver/CustomerAddressCustomAttributeFilter.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,64 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CustomerGraphQl\Model\Resolver; | ||
|
||
use Magento\CustomerGraphQl\Model\Customer\Address\ExtractCustomerAddressData; | ||
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress; | ||
use Magento\Framework\Api\CustomAttributesDataInterface; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
/** | ||
* Resolver Customer Address Custom Attribute filter | ||
*/ | ||
class CustomerAddressCustomAttributeFilter implements ResolverInterface | ||
{ | ||
/** | ||
* @var GetCustomerAddress | ||
*/ | ||
private GetCustomerAddress $getCustomerAddress; | ||
|
||
/** | ||
* @var ExtractCustomerAddressData | ||
*/ | ||
private ExtractCustomerAddressData $extractCustomerAddressData; | ||
|
||
/** | ||
* @param GetCustomerAddress $getCustomerAddress | ||
* @param ExtractCustomerAddressData $extractCustomerAddressData | ||
*/ | ||
public function __construct( | ||
GetCustomerAddress $getCustomerAddress, | ||
ExtractCustomerAddressData $extractCustomerAddressData, | ||
) { | ||
$this->getCustomerAddress = $getCustomerAddress; | ||
$this->extractCustomerAddressData = $extractCustomerAddressData; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
): array { | ||
$customAttributes = $value[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES . 'V2']; | ||
if (isset($args['uids']) && !empty($args['uids'])) { | ||
$selectedUids = array_values($args['uids']); | ||
return array_filter($customAttributes, function ($attr) use ($selectedUids) { | ||
return in_array($attr['uid'], $selectedUids); | ||
}); | ||
} | ||
|
||
return $customAttributes; | ||
} | ||
} |
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
Oops, something went wrong.