Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Model/Write/EavIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ class EavIterator implements IteratorAggregate
*/
private array $parentRelations = [];

/**
* @var array
*/
private array $parentRelationsImageAttributes = [];

/**
* EavIterator constructor.
*
Expand Down Expand Up @@ -276,6 +281,7 @@ public function getIterator(): \Traversable
$this->setEntityIds($entityIds);
if ($this->config->isGroupedExport($this->store) && $this->entityCode === Product::ENTITY) {
$this->preloadParentRelations($entityIds);
$this->preloadConfigurableImageData();
}

$select = $this->createSelect();
Expand Down Expand Up @@ -303,6 +309,7 @@ public function getIterator(): \Traversable
isset($this->parentRelations[$result['entity_id']])
) {
$result['parent_id'] = $this->parentRelations[$result['entity_id']];
$result = $this->setImagesAttributesFromConfigurable($result);
}

yield $result;
Expand Down Expand Up @@ -576,4 +583,50 @@ protected function preloadParentRelations(array $productIds): void

$this->parentRelations = $connection->fetchPairs($select);
}

/**
* @return void
*/
protected function preloadConfigurableImageData(): void
{
$uniqueConfigurableIds = array_unique($this->parentRelations);
if (empty($uniqueConfigurableIds)) {
return;
}

$imageAttributes = ['image', 'small_image', 'thumbnail'];
$connection = $this->getConnection();
$select = $connection->select()
->from(
['cpev' => 'catalog_product_entity_varchar'],
['entity_id' => 'cpev.entity_id', 'value' => 'cpev.value']
)
->join(
['ea' => 'eav_attribute'],
'ea.attribute_id = cpev.attribute_id',
['attribute_code' => 'ea.attribute_code']
)
->where('ea.attribute_code IN (?)', $imageAttributes)
->where('cpev.entity_id IN (?)', $uniqueConfigurableIds);

$result = $connection->fetchAll($select);
foreach ($result as $row) {
$this->parentRelationsImageAttributes[$row['entity_id']][$row['attribute_code']] = $row['value'];
}
}

/**
* @param array $attributes
*
* @return array
*/
protected function setImagesAttributesFromConfigurable(array $attributes): array
{
$parentId = $attributes['parent_id'];
foreach ($this->parentRelationsImageAttributes[$parentId] ?? [] as $attribute => $attributeValue) {
$attributes[$attribute] = $attributeValue;
}

return $attributes;
}
}