Commit 5b3b07c7 by halweg

fix : fix base image

parent 412b1882
......@@ -43,11 +43,9 @@ class ProductFirstImageAsBaseFixer extends Command
foreach ($collection as $item) {
$pid = $item->getId();
if ($pid == '8822') {
$this->fixBaseImage($input, $output, $pid);
}
}
}
protected function fixBaseImage($input, $output, $productId)
{
......@@ -55,25 +53,12 @@ class ProductFirstImageAsBaseFixer extends Command
$firstImage = $this->imageQueryResource->getFirstImages($productId);
$output->writeln('first image' . $firstImage);
$output->writeln("main image".$mainImage);
if ($mainImage != $firstImage) {
$output->writeln('fix product ' . $mainImage . ' product id: ' . $productId);
$otherImages = $this->imageQueryResource->getAllImages($productId);
foreach ($otherImages as $image) {
$position = 1;
if ($image['value'] == $mainImage) {
$this->imageQueryResource->updatePosition((int)$image['value_id'], $position);
}
}
reset($otherImages);
foreach ($otherImages as $image) {
if ($image['value'] != $mainImage) {
$position++;
$this->imageQueryResource->updatePosition((int)$image['value_id'], $position);
}
}
//change main image
$this->imageQueryResource->changeBaseImageTo($productId, $firstImage);
}
}
}
\ No newline at end of file
......@@ -90,10 +90,22 @@ class ImageQueryResource
public function updatePosition(int $valueId, int $position)
{
$this->resourceConnection->getConnection()->update(
/*$this->resourceConnection->getConnection()->update(
$this->resourceConnection->getTableName('catalog_product_entity_media_gallery_value'),
['position' => $position],
['value_id=?' => $valueId]
);*/
}
public function changeBaseImageTo($productId, $firstImage)
{
$this->resourceConnection->getConnection()->update(
$this->resourceConnection->getTableName('catalog_product_entity_varchar'),
['value' => $firstImage],
[
'entity_id=?' => $productId,
'attribute_id=?' => 87
],
);
}
......
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