@@ -346,9 +346,11 @@ public function getCollection($storeId)
346346 // First, collect all product data without loading images
347347 $ productRows = [];
348348 $ productIds = [];
349+ $ linkField = $ this ->_productResource ->getLinkField ();
350+
349351 while ($ row = $ query ->fetch ()) {
350352 $ productRows [] = $ row ;
351- $ productIds [] = $ row [$ this -> getIdFieldName () ];
353+ $ productIds [] = $ row [$ linkField ];
352354 }
353355
354356 // Pre-load all images in batch to avoid N+1 queries
@@ -442,12 +444,13 @@ protected function _loadProductImages($product, $storeId)
442444 */
443445 protected function _getAllProductImages ($ product , $ storeId )
444446 {
445- $ productId = $ product ->getId ();
447+ $ linkField = $ this ->_productResource ->getLinkField ();
448+ $ productRowId = $ product ->getData ($ linkField );
446449 $ imagesCollection = [];
447450
448451 // Use cached images if available (from batch loading)
449- if (isset ($ this ->_productImagesCache [$ productId ])) {
450- $ gallery = $ this ->_productImagesCache [$ productId ];
452+ if (isset ($ this ->_productImagesCache [$ productRowId ])) {
453+ $ gallery = $ this ->_productImagesCache [$ productRowId ];
451454 foreach ($ gallery as $ image ) {
452455 $ imagesCollection [] = new DataObject (
453456 [
@@ -457,7 +460,7 @@ protected function _getAllProductImages($product, $storeId)
457460 );
458461 }
459462 } else {
460- // Fallback to individual query (should rarely happen now)
463+ // Fallback to individual query
461464 $ product ->setStoreId ($ storeId );
462465 $ gallery = $ this ->mediaGalleryResourceModel ->loadProductGalleryByAttributeId (
463466 $ product ,
0 commit comments