Skip to content

Commit fe30143

Browse files
Sort images by position
1 parent 0cd4271 commit fe30143

File tree

1 file changed

+10
-1
lines changed
  • Service/ProductData/AttributeCollector/Data

1 file changed

+10
-1
lines changed

Service/ProductData/AttributeCollector/Data/Image.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,22 @@ private function combineData(array $imagesData, array $typesData): array
172172
$position = $imageData['position'];
173173
$imageValue = $imageData['value'];
174174

175-
$result[$entityId][$storeId][$position] = [
175+
$result[$entityId][$storeId][] = [
176176
'file' => $this->getMediaUrl('catalog/product' . $imageValue),
177177
'position' => $position,
178178
'types' => $typesData[$entityId][$imageValue][$storeId] ?? []
179179
];
180180
}
181181

182+
// Sort by position ascending
183+
foreach ($result as &$stores) {
184+
foreach ($stores as &$images) {
185+
usort($images, function ($a, $b) {
186+
return (int)$a['position'] <=> (int)$b['position'];
187+
});
188+
}
189+
}
190+
182191
return $result;
183192
}
184193
/**

0 commit comments

Comments
 (0)