66
77namespace Mollie \Subscriptions \Model ;
88
9+ use DateInterval ;
10+ use DateTimeImmutable ;
911use Magento \Customer \Api \CustomerRepositoryInterface ;
1012use Magento \Customer \Api \Data \CustomerInterface ;
1113use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
@@ -93,12 +95,16 @@ public function getDataSourceData()
9395 $ api = $ this ->mollieSubscriptionApi ->loadByStore ($ storeId );
9496 $ paging = $ this ->getContext ()->getRequestParam ('paging ' );
9597
96- $ pageSize = $ paging ['pageSize ' ] ?? 20 ;
98+ $ pageSize = $ paging ['pageSize ' ] ?? null ;
9799 if ($ pageSize > 250 ) {
98100 $ pageSize = 250 ;
99101 }
100102
101- $ result = $ api ->subscriptions ->page (
103+ if (!$ this ->getContext ()->getRequestParam ('offsetID ' )) {
104+ $ pageSize = null ;
105+ }
106+
107+ $ result = $ api ->subscriptions ->allFor (
102108 $ this ->getContext ()->getRequestParam ('offsetID ' ),
103109 $ pageSize
104110 );
@@ -110,8 +116,8 @@ public function getDataSourceData()
110116 $ items = array_map (function (Subscription $ subscription ) use ($ daysBeforeReminder ) {
111117 $ prePaymentReminder = null ;
112118 if ($ subscription ->nextPaymentDate ) {
113- $ prePaymentReminder = new \ DateTimeImmutable ($ subscription ->nextPaymentDate );
114- $ prePaymentReminder = $ prePaymentReminder ->sub (new \ DateInterval ('P ' . $ daysBeforeReminder . 'D ' ));
119+ $ prePaymentReminder = new DateTimeImmutable ($ subscription ->nextPaymentDate );
120+ $ prePaymentReminder = $ prePaymentReminder ->sub (new DateInterval ('P ' . $ daysBeforeReminder . 'D ' ));
115121 }
116122
117123 $ response = new SubscriptionResponse (
@@ -132,23 +138,6 @@ public function getDataSourceData()
132138 ];
133139 }
134140
135- private function preloadCustomers (array $ result )
136- {
137- $ mollieCustomerIds = array_column ($ result , 'customerId ' );
138-
139- $ searchCriteria = $ this ->searchCriteriaBuilderFactory ->create ();
140- $ searchCriteria ->addFilter ('mollie_customer_id ' , $ mollieCustomerIds , 'in ' );
141- $ result = $ this ->mollieCustomerRepository ->getList ($ searchCriteria ->create ());
142-
143- $ customerIds = array_map (function (MollieCustomerInterface $ customerInfo ) {
144- return $ customerInfo ->getCustomerId ();
145- }, $ result ->getItems ());
146-
147- $ searchCriteria = $ this ->searchCriteriaBuilderFactory ->create ();
148- $ searchCriteria ->addFilter ('entity_id ' , $ customerIds , 'in ' );
149- $ this ->customers = $ this ->customerRepository ->getList ($ searchCriteria ->create ())->getItems ();
150- }
151-
152141 private function getCustomerMollieCustomerById (string $ customerId )
153142 {
154143 foreach ($ this ->customers as $ customer ) {
@@ -160,6 +149,14 @@ private function getCustomerMollieCustomerById(string $customerId)
160149 return $ this ->customerFactory ->create ();
161150 }
162151
152+ private function parseLink (string $ link ): string
153+ {
154+ $ query = parse_url ($ link , PHP_URL_QUERY );
155+ parse_str ($ query , $ parts );
156+
157+ return $ parts ['from ' ];
158+ }
159+
163160 private function parsePreviousNext (SubscriptionCollection $ result )
164161 {
165162 if ($ result ->hasNext ()) {
@@ -171,11 +168,20 @@ private function parsePreviousNext(SubscriptionCollection $result)
171168 }
172169 }
173170
174- private function parseLink ( string $ link ): string
171+ private function preloadCustomers ( array $ result )
175172 {
176- $ query = parse_url ($ link , PHP_URL_QUERY );
177- parse_str ($ query , $ parts );
173+ $ mollieCustomerIds = array_column ($ result , 'customerId ' );
178174
179- return $ parts ['from ' ];
175+ $ searchCriteria = $ this ->searchCriteriaBuilderFactory ->create ();
176+ $ searchCriteria ->addFilter ('mollie_customer_id ' , $ mollieCustomerIds , 'in ' );
177+ $ result = $ this ->mollieCustomerRepository ->getList ($ searchCriteria ->create ());
178+
179+ $ customerIds = array_map (function (MollieCustomerInterface $ customerInfo ) {
180+ return $ customerInfo ->getCustomerId ();
181+ }, $ result ->getItems ());
182+
183+ $ searchCriteria = $ this ->searchCriteriaBuilderFactory ->create ();
184+ $ searchCriteria ->addFilter ('entity_id ' , $ customerIds , 'in ' );
185+ $ this ->customers = $ this ->customerRepository ->getList ($ searchCriteria ->create ())->getItems ();
180186 }
181187}
0 commit comments