@@ -44,6 +44,11 @@ class UpdateCustomerAccount
44
44
*/
45
45
private $ changeSubscriptionStatus ;
46
46
47
+ /**
48
+ * @var GetAllowedCustomerAttributes
49
+ */
50
+ private $ getAllowedCustomerAttributes ;
51
+
47
52
/**
48
53
* @var array
49
54
*/
@@ -55,6 +60,7 @@ class UpdateCustomerAccount
55
60
* @param CheckCustomerPassword $checkCustomerPassword
56
61
* @param DataObjectHelper $dataObjectHelper
57
62
* @param ChangeSubscriptionStatus $changeSubscriptionStatus
63
+ * @param GetAllowedCustomerAttributes $getAllowedCustomerAttributes
58
64
* @param array $restrictedKeys
59
65
*/
60
66
public function __construct (
@@ -63,6 +69,7 @@ public function __construct(
63
69
CheckCustomerPassword $ checkCustomerPassword ,
64
70
DataObjectHelper $ dataObjectHelper ,
65
71
ChangeSubscriptionStatus $ changeSubscriptionStatus ,
72
+ GetAllowedCustomerAttributes $ getAllowedCustomerAttributes ,
66
73
array $ restrictedKeys = []
67
74
) {
68
75
$ this ->saveCustomer = $ saveCustomer ;
@@ -71,6 +78,7 @@ public function __construct(
71
78
$ this ->dataObjectHelper = $ dataObjectHelper ;
72
79
$ this ->restrictedKeys = $ restrictedKeys ;
73
80
$ this ->changeSubscriptionStatus = $ changeSubscriptionStatus ;
81
+ $ this ->getAllowedCustomerAttributes = $ getAllowedCustomerAttributes ;
74
82
}
75
83
76
84
/**
@@ -93,7 +101,7 @@ public function execute(CustomerInterface $customer, array $data): void
93
101
$ this ->checkCustomerPassword ->execute ($ data ['password ' ], (int )$ customer ->getId ());
94
102
$ customer ->setEmail ($ data ['email ' ]);
95
103
}
96
-
104
+ $ this -> validateData ( $ data );
97
105
$ filteredData = array_diff_key ($ data , array_flip ($ this ->restrictedKeys ));
98
106
$ this ->dataObjectHelper ->populateWithArray ($ customer , $ filteredData , CustomerInterface::class);
99
107
@@ -105,4 +113,29 @@ public function execute(CustomerInterface $customer, array $data): void
105
113
$ this ->changeSubscriptionStatus ->execute ((int )$ customer ->getId (), (bool )$ data ['is_subscribed ' ]);
106
114
}
107
115
}
116
+
117
+ /**
118
+ * @param array $customerData
119
+ * @return void
120
+ * @throws GraphQlInputException
121
+ */
122
+ public function validateData (array $ customerData ): void
123
+ {
124
+ $ attributes = $ this ->getAllowedCustomerAttributes ->execute ();
125
+ $ errorInput = [];
126
+
127
+ foreach ($ attributes as $ attributeName => $ attributeInfo ) {
128
+ if ($ attributeInfo ->getIsRequired ()
129
+ && (isset ($ customerData [$ attributeName ]) && empty ($ customerData [$ attributeName ]))
130
+ ) {
131
+ $ errorInput [] = $ attributeName ;
132
+ }
133
+ }
134
+
135
+ if ($ errorInput ) {
136
+ throw new GraphQlInputException (
137
+ __ ('Required parameters are missing: %1 ' , [implode (', ' , $ errorInput )])
138
+ );
139
+ }
140
+ }
108
141
}
0 commit comments