8
8
namespace Magento \CustomerGraphQl \Model \Customer ;
9
9
10
10
use Magento \Customer \Api \CustomerMetadataManagementInterface ;
11
+ use Magento \Customer \Api \Data \CustomerInterface ;
12
+ use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
11
13
use Magento \Eav \Model \AttributeRepository ;
12
14
use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
13
15
use Magento \Framework \Api \SearchCriteriaBuilder ;
14
16
use Magento \Framework \Exception \InputException ;
15
17
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
18
+ use Magento \Framework \Reflection \DataObjectProcessor ;
16
19
17
20
/**
18
21
* Get allowed address attributes
@@ -24,19 +27,38 @@ class GetAllowedCustomerAttributes
24
27
*/
25
28
private $ attributeRepository ;
26
29
30
+ /**
31
+ * @var CustomerInterfaceFactory\
32
+ */
33
+ private $ customerDataFactory ;
34
+
35
+ /**
36
+ * @var DataObjectProcessor
37
+ */
38
+ private $ dataObjectProcessor ;
39
+
27
40
/**
28
41
* @var SearchCriteriaBuilder
29
42
*/
30
43
private $ searchCriteriaBuilder ;
31
44
32
45
/**
46
+ * GetAllowedCustomerAttributes constructor.
47
+ *
33
48
* @param AttributeRepository $attributeRepository
49
+ * @param CustomerInterfaceFactory $customerDataFactory
50
+ * @param DataObjectProcessor $dataObjectProcessor
51
+ * @param SearchCriteriaBuilder $searchCriteriaBuilder
34
52
*/
35
53
public function __construct (
36
54
AttributeRepository $ attributeRepository ,
55
+ CustomerInterfaceFactory $ customerDataFactory ,
56
+ DataObjectProcessor $ dataObjectProcessor ,
37
57
SearchCriteriaBuilder $ searchCriteriaBuilder
38
58
) {
39
59
$ this ->attributeRepository = $ attributeRepository ;
60
+ $ this ->customerDataFactory = $ customerDataFactory ;
61
+ $ this ->dataObjectProcessor = $ dataObjectProcessor ;
40
62
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
41
63
}
42
64
@@ -49,6 +71,13 @@ public function __construct(
49
71
*/
50
72
public function execute ($ attributeKeys ): array
51
73
{
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 ));
52
81
$ this ->searchCriteriaBuilder ->addFilter ('attribute_code ' , $ attributeKeys , 'in ' );
53
82
$ searchCriteria = $ this ->searchCriteriaBuilder ->create ();
54
83
try {
0 commit comments