@@ -104,19 +104,22 @@ private function loadCustomersData(array $customerIdentifiers): void
104104 };
105105 $ offset = 0 ;
106106 for ($ chunk = $ getChuck ($ offset ); !empty ($ chunk ); $ offset += $ pageSize , $ chunk = $ getChuck ($ offset )) {
107- $ emails = array_column ($ chunk , 'email ' );
107+ $ customerWebsites = array_reduce ($ chunk , function ($ customerWebsiteByEmail , $ customer ) {
108+ $ customerWebsiteByEmail [$ customer ['email ' ]][] = $ customer ['website_id ' ];
109+ return $ customerWebsiteByEmail ;
110+ });
108111 $ chunkSelect = clone $ select ;
109- $ chunkSelect ->where ($ customerTableId . '.email IN (?) ' , $ emails );
112+ $ chunkSelect ->where ($ customerTableId . '.email IN (?) ' , array_keys ( $ customerWebsites ) );
110113 $ customers = $ collection ->getConnection ()->fetchAll ($ chunkSelect );
114+ $ i = 0 ;
111115 foreach ($ customers as $ customer ) {
112116 $ this ->addCustomerByArray ($ customer );
113- if ($ this ->configShare ->isGlobalScope () &&
114- is_array (current ($ customerIdentifiers )) &&
115- count (current ($ customerIdentifiers )) > 0 &&
116- isset (current ($ customerIdentifiers )['website_id ' ]) &&
117- $ customer ['website_id ' ] !== (string ) current ($ customerIdentifiers )['website_id ' ]
117+ if (
118+ $ this ->configShare ->isGlobalScope () &&
119+ !in_array ((int ) $ customer ['website_id ' ], $ customerWebsites [$ customer ['email ' ]], true )
118120 ) {
119- $ customer ['website_id ' ] = (string ) current ($ customerIdentifiers )['website_id ' ];
121+ $ customer ['website_id ' ] = $ customerWebsites [$ customer ['email ' ]][$ i ];
122+ $ i ++;
120123 $ this ->addCustomerByArray ($ customer );
121124 }
122125 }
0 commit comments