Commit 84ad8771 by halweg

fix : change base img break when last image

parent 8f5d7685
......@@ -65,6 +65,12 @@ class ProductFirstImageAsBaseFixer extends Command
return;
}
$lastImage = $this->imageQueryResource->getLastImage($productId);
if ($mainImage != $lastImage) {
$output->writeln('base image not last, break');
return;
}
if ($mainImage != $firstImage) {
$output->writeln('fix product ' . $mainImage . ' product id: ' . $productId);
//change main image
......
......@@ -109,4 +109,23 @@ class ImageQueryResource
);
}
public function getLastImage($productId)
{
$select = $this->resourceConnection->getConnection()->select();
$select->from(['v' => $this->resourceConnection->getTableName('catalog_product_entity_media_gallery_value')]);
$select->join(
['g' => 'catalog_product_entity_media_gallery'],
'g.value_id=v.value_id',
[]
);
$select->where('entity_id=?', $productId);
$select->reset(\Magento\Framework\DB\Select::COLUMNS);
$select->columns(['g.value', 'v.position']);
$select->order('v.position DESC');
$select->limit(1);
return $this->resourceConnection->getConnection()->fetchOne($select);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment