13
13
use Magento \Framework \Api \DataObjectHelper ;
14
14
use Magento \Framework \Exception \LocalizedException ;
15
15
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
16
+ use Magento \Framework \Reflection \DataObjectProcessor ;
16
17
use Magento \Store \Model \StoreManagerInterface ;
17
18
18
19
/**
@@ -50,6 +51,11 @@ class CreateCustomerAccount
50
51
*/
51
52
private $ validateCustomerData ;
52
53
54
+ /**
55
+ * @var DataObjectProcessor
56
+ */
57
+ private $ dataObjectProcessor ;
58
+
53
59
/**
54
60
* CreateCustomerAccount constructor.
55
61
*
@@ -58,6 +64,7 @@ class CreateCustomerAccount
58
64
* @param StoreManagerInterface $storeManager
59
65
* @param AccountManagementInterface $accountManagement
60
66
* @param ChangeSubscriptionStatus $changeSubscriptionStatus
67
+ * @param DataObjectProcessor $dataObjectProcessor
61
68
* @param ValidateCustomerData $validateCustomerData
62
69
*/
63
70
public function __construct (
@@ -66,6 +73,7 @@ public function __construct(
66
73
StoreManagerInterface $ storeManager ,
67
74
AccountManagementInterface $ accountManagement ,
68
75
ChangeSubscriptionStatus $ changeSubscriptionStatus ,
76
+ DataObjectProcessor $ dataObjectProcessor ,
69
77
ValidateCustomerData $ validateCustomerData
70
78
) {
71
79
$ this ->dataObjectHelper = $ dataObjectHelper ;
@@ -74,6 +82,7 @@ public function __construct(
74
82
$ this ->storeManager = $ storeManager ;
75
83
$ this ->changeSubscriptionStatus = $ changeSubscriptionStatus ;
76
84
$ this ->validateCustomerData = $ validateCustomerData ;
85
+ $ this ->dataObjectProcessor = $ dataObjectProcessor ;
77
86
}
78
87
79
88
/**
@@ -106,8 +115,16 @@ public function execute(array $data): CustomerInterface
106
115
*/
107
116
private function createAccount (array $ data ): CustomerInterface
108
117
{
109
- $ this ->validateCustomerData ->execute ($ data , true );
110
118
$ customerDataObject = $ this ->customerFactory ->create ();
119
+ /**
120
+ * Add required attributes for customer entity
121
+ */
122
+ $ requiredDataAttributes = $ this ->dataObjectProcessor ->buildOutputDataArray (
123
+ $ customerDataObject ,
124
+ CustomerInterface::class
125
+ );
126
+ $ data = array_merge ($ requiredDataAttributes , $ data );
127
+ $ this ->validateCustomerData ->execute ($ data );
111
128
$ this ->dataObjectHelper ->populateWithArray (
112
129
$ customerDataObject ,
113
130
$ data ,
0 commit comments