Skip to content

Commit b4db736

Browse files
committed
magento#271: [My Account] Adding required attributes from customer data model to validation
1 parent d071027 commit b4db736

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

app/code/Magento/CustomerGraphQl/Model/Customer/GetAllowedCustomerAttributes.php

+29
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
namespace Magento\CustomerGraphQl\Model\Customer;
99

1010
use Magento\Customer\Api\CustomerMetadataManagementInterface;
11+
use Magento\Customer\Api\Data\CustomerInterface;
12+
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
1113
use Magento\Eav\Model\AttributeRepository;
1214
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1315
use Magento\Framework\Api\SearchCriteriaBuilder;
1416
use Magento\Framework\Exception\InputException;
1517
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
18+
use Magento\Framework\Reflection\DataObjectProcessor;
1619

1720
/**
1821
* Get allowed address attributes
@@ -24,19 +27,38 @@ class GetAllowedCustomerAttributes
2427
*/
2528
private $attributeRepository;
2629

30+
/**
31+
* @var CustomerInterfaceFactory\
32+
*/
33+
private $customerDataFactory;
34+
35+
/**
36+
* @var DataObjectProcessor
37+
*/
38+
private $dataObjectProcessor;
39+
2740
/**
2841
* @var SearchCriteriaBuilder
2942
*/
3043
private $searchCriteriaBuilder;
3144

3245
/**
46+
* GetAllowedCustomerAttributes constructor.
47+
*
3348
* @param AttributeRepository $attributeRepository
49+
* @param CustomerInterfaceFactory $customerDataFactory
50+
* @param DataObjectProcessor $dataObjectProcessor
51+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
3452
*/
3553
public function __construct(
3654
AttributeRepository $attributeRepository,
55+
CustomerInterfaceFactory $customerDataFactory,
56+
DataObjectProcessor $dataObjectProcessor,
3757
SearchCriteriaBuilder $searchCriteriaBuilder
3858
) {
3959
$this->attributeRepository = $attributeRepository;
60+
$this->customerDataFactory = $customerDataFactory;
61+
$this->dataObjectProcessor = $dataObjectProcessor;
4062
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
4163
}
4264

@@ -49,6 +71,13 @@ public function __construct(
4971
*/
5072
public function execute($attributeKeys): array
5173
{
74+
/** @var CustomerInterface $customerDataDummy */
75+
$customerDataDummy = $this->customerDataFactory->create();
76+
$requiredDataAttributes = $this->dataObjectProcessor->buildOutputDataArray(
77+
$customerDataDummy,
78+
CustomerInterface::class
79+
);
80+
$attributeKeys = array_merge($attributeKeys, array_keys($requiredDataAttributes));
5281
$this->searchCriteriaBuilder->addFilter('attribute_code', $attributeKeys, 'in');
5382
$searchCriteria = $this->searchCriteriaBuilder->create();
5483
try {

0 commit comments

Comments
 (0)