@@ -104,19 +104,22 @@ private function loadCustomersData(array $customerIdentifiers): void
104
104
};
105
105
$ offset = 0 ;
106
106
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
+ });
108
111
$ chunkSelect = clone $ select ;
109
- $ chunkSelect ->where ($ customerTableId . '.email IN (?) ' , $ emails );
112
+ $ chunkSelect ->where ($ customerTableId . '.email IN (?) ' , array_keys ( $ customerWebsites ) );
110
113
$ customers = $ collection ->getConnection ()->fetchAll ($ chunkSelect );
114
+ $ i = 0 ;
111
115
foreach ($ customers as $ customer ) {
112
116
$ 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 )
118
120
) {
119
- $ customer ['website_id ' ] = (string ) current ($ customerIdentifiers )['website_id ' ];
121
+ $ customer ['website_id ' ] = $ customerWebsites [$ customer ['email ' ]][$ i ];
122
+ $ i ++;
120
123
$ this ->addCustomerByArray ($ customer );
121
124
}
122
125
}
0 commit comments