11
11
use Magento \Customer \Api \AccountManagementInterface ;
12
12
use Magento \Customer \Api \Data \CustomerInterface ;
13
13
use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
14
+ use Magento \CustomerGraphQl \Model \Customer \ChangeSubscriptionStatus ;
14
15
use Magento \CustomerGraphQl \Model \Customer \CustomerDataProvider ;
15
16
use Magento \Framework \Api \DataObjectHelper ;
16
17
use Magento \Framework \Exception \LocalizedException ;
22
23
use Magento \Newsletter \Model \SubscriberFactory ;
23
24
use Magento \Store \Model \StoreManagerInterface ;
24
25
25
- /**
26
- * Create customer data resolver
27
- */
28
26
class CreateCustomer implements ResolverInterface
29
27
{
30
28
/**
31
29
* @var CustomerDataProvider
32
30
*/
33
31
private $ customerDataProvider ;
34
-
35
32
/**
36
33
* @var AccountManagementInterface
37
34
*/
38
35
private $ accountManagement ;
39
-
40
36
/**
41
37
* @var CustomerInterfaceFactory
42
38
*/
43
39
private $ customerFactory ;
44
-
45
40
/**
46
41
* @var DataObjectHelper
47
42
*/
@@ -54,6 +49,10 @@ class CreateCustomer implements ResolverInterface
54
49
* @var SubscriberFactory
55
50
*/
56
51
private $ subscriberFactory ;
52
+ /**
53
+ * @var ChangeSubscriptionStatus
54
+ */
55
+ private $ changeSubscriptionStatus ;
57
56
58
57
/**
59
58
* @param DataObjectHelper $dataObjectHelper
@@ -62,21 +61,24 @@ class CreateCustomer implements ResolverInterface
62
61
* @param StoreManagerInterface $storeManager
63
62
* @param SubscriberFactory $subscriberFactory
64
63
* @param CustomerDataProvider $customerDataProvider
64
+ * @param ChangeSubscriptionStatus $changeSubscriptionStatus
65
65
*/
66
66
public function __construct (
67
67
DataObjectHelper $ dataObjectHelper ,
68
68
CustomerInterfaceFactory $ customerFactory ,
69
69
AccountManagementInterface $ accountManagement ,
70
70
StoreManagerInterface $ storeManager ,
71
71
SubscriberFactory $ subscriberFactory ,
72
- CustomerDataProvider $ customerDataProvider
72
+ CustomerDataProvider $ customerDataProvider ,
73
+ ChangeSubscriptionStatus $ changeSubscriptionStatus
73
74
) {
74
75
$ this ->customerDataProvider = $ customerDataProvider ;
75
76
$ this ->accountManagement = $ accountManagement ;
76
77
$ this ->customerFactory = $ customerFactory ;
77
78
$ this ->dataObjectHelper = $ dataObjectHelper ;
78
79
$ this ->storeManager = $ storeManager ;
79
80
$ this ->subscriberFactory = $ subscriberFactory ;
81
+ $ this ->changeSubscriptionStatus = $ changeSubscriptionStatus ;
80
82
}
81
83
82
84
/**
@@ -94,13 +96,14 @@ public function resolve(
94
96
}
95
97
try {
96
98
$ customer = $ this ->createUserAccount ($ args );
99
+ $ customerId = (int )$ customer ->getId ();
97
100
$ this ->setUpUserContext ($ context , $ customer );
98
101
if (array_key_exists ('is_subscribed ' , $ args ['input ' ])) {
99
102
if ($ args ['input ' ]['is_subscribed ' ]) {
100
- $ this ->subscriberFactory -> create ()-> subscribeCustomerById ( $ customer -> getId () );
103
+ $ this ->changeSubscriptionStatus -> execute ( $ customerId , true );
101
104
}
102
105
}
103
- $ data = $ this ->customerDataProvider ->getCustomerById (( int ) $ customer -> getId () );
106
+ $ data = $ this ->customerDataProvider ->getCustomerById ($ customerId );
104
107
} catch (LocalizedException $ e ) {
105
108
throw new GraphQlInputException (__ ($ e ->getMessage ()));
106
109
}
0 commit comments