16
16
use Magento \Framework \Exception \LocalizedException ;
17
17
use Magento \Newsletter \Model \Subscriber ;
18
18
use Magento \Store \Model \StoreManagerInterface ;
19
+ use Magento \Newsletter \Model \ResourceModel \Subscriber \CollectionFactory as SubscriberCollection ;
19
20
20
21
/**
21
22
* Profiles web API service class
@@ -56,6 +57,8 @@ class Profiles
56
57
*/
57
58
private $ addressRepository ;
58
59
60
+ private $ subscriberCollection ;
61
+
59
62
/**
60
63
* Profiles constructor.
61
64
*
@@ -72,14 +75,16 @@ public function __construct(
72
75
CustomerRepositoryInterface $ customerRepository ,
73
76
SearchCriteriaBuilder $ searchCriteriaBuilder ,
74
77
CustomerResource $ customerResource ,
75
- AddressRepository $ addressRepository
78
+ AddressRepository $ addressRepository ,
79
+ SubscriberCollection $ subscriberCollection
76
80
) {
77
81
$ this ->subscriber = $ subscriber ;
78
82
$ this ->storeManager = $ storeManager ;
79
83
$ this ->customerRepository = $ customerRepository ;
80
84
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
81
85
$ this ->customerResource = $ customerResource ;
82
86
$ this ->addressRepository = $ addressRepository ;
87
+ $ this ->subscriberCollection = $ subscriberCollection ;
83
88
}
84
89
85
90
/**
@@ -97,6 +102,9 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
97
102
$ mainData = [
98
103
"id " => $ customer ->getId (),
99
104
"email " => $ customer ->getEmail (),
105
+ "first_name " => $ customer ->getFirstname (),
106
+ "middle_name " => $ customer ->getMiddlename (),
107
+ "last_name " => $ customer ->getLastname (),
100
108
"gender " => $ this ->getGender ($ customer ),
101
109
"active " => true ,
102
110
"subscribed_to_newsletter " => $ this ->isSubscribed ($ customer ),
@@ -121,6 +129,17 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
121
129
122
130
$ data [] = $ mainData ;
123
131
}
132
+
133
+ $ subscribers = $ this ->subscriberCollection ->create ()
134
+ ->addFieldToFilter ('customer_id ' , ['eq ' => 0 ]);
135
+ foreach ($ subscribers as $ subscriber ) {
136
+ $ data [] = [
137
+ 'id ' => null ,
138
+ 'email ' => $ subscriber ->getSubscriberEmail (),
139
+ 'subscribed_to_newsletter ' => $ subscriber ->getSubscriberStatus ()
140
+ ];
141
+ }
142
+
124
143
return $ data ;
125
144
}
126
145
0 commit comments