-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Product image roles randomly disappear #10687
Comments
This is a big issue for us. Any news when this will be fixed? |
@boxyman, thank you for your report. |
I think it's only when you save a product programmatically. The problem that I found it when you set the current store to admin..
|
@kervin Unfortunately, we could not reproduce the issue as you described it. Please add more details to your description of the steps you followed when identifying this issue. Screenshots or logs would be helpful, too. |
Just do the following on 2.1.8. If I do not set current store, it saves products to the default store view.. when I set the store, it breaks the images.
|
I found a workaround, unset media_gallery, if you are not changing images.
|
I got the same issue with Magento 2.2.0. Some my customers have updated their websites from 2.1.8 to 2.2.0 and all custom extensions used $this->productRepository->save($product); will unset value of image properties "base", "small" and "thumbnails" . We see placeholder images only! $product->unsetData('media_gallery'); Two lines of code are great to fix this issue, however, it can make a critical error on the catalog_product_view page. 1 exception(s): This issue is the same with #10461 and it must be fixed quickly! |
I have the same issue with Magento 2.1.9. In my installation it only happens when the product is saved in a cron task. If I run the same code using the cli tool the images keep their roles. |
@boxyman, thank you for your report. |
To fix magento#10687 - adds the 'types' key to the $images array to provide existing image roles (if not set), which are re-attributed after clearMediaAttribute() is called
I think its issue on Magento 2.2.3 or below version Open root/app/code/Magento/Catalog/Model/ProductRepository.php protected function processMediaGallery(ProductInterface $product, $mediaGalleryEntries) I have make this patched and its working for me.( See : #10461 (comment) ) |
Quick heads up for anyone who finds this issue because their image roles randomly disappears but you are not doing anything with the productRepository. Its enough that a Class that you are using i saving though the product repository to lose your image roles. I saved tier prices through Magento\Catalog\Model\Product\ScopedTierPriceManagement and this is using the product repository so i lost my image roles. Tested in 2.2.3 |
We have a customer's shop, where image roles disappeared. Now we're trying to get them back, but none of the possible solutions here work, apparently. Magento version is 2.1.12. Anyone have any idea how to get the roles back? |
Hi @boxyman. Thank you for your report. The fix will be available with the upcoming 2.2.7 release. |
Hi @boxyman. Thank you for your report.
The fix will be available with the upcoming 2.1.16 release. |
The code fix is not present in 2.2.6, this looks still to be an issue. Any updates ? |
@skdude because the fix was provided in 2.2.7 (Release: 2.2.7). |
I'm having this issue in 2.3.3 - how do we fix? |
Also having this issue in 2.3.3. |
Yes exactly what is happening for us too. |
Had the same issue today with a client, easiest fix we found was to just reset the missing roles to the first image in the gallery. <?php
ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);
use Magento\Framework\App\State;
use Magento\Framework\App\Bootstrap;
require 'app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get(State::class);
$state->setAreaCode('frontend');
$pri = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$smi = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
$smdl = $smi->getStores();
$stores = [0 => 'global'];
foreach ($smdl as $k => $v) {
$stores[$k] = $v['code'];
}
foreach ($stores as $k => $v) {
$smi->setCurrentStore($k);
echo str_repeat('-', 20), PHP_EOL;
echo "Processing {$k} ({$v})", PHP_EOL;
echo str_repeat('-', 20), PHP_EOL;
$collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class)->create()->addAttributeToSelect('*');
foreach ($collection as $product) {
$objectManager->get("Magento\Catalog\Model\Product\Gallery\ReadHandler")->execute($product);
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
if (!is_iterable($existingMediaGalleryEntries) || count($existingMediaGalleryEntries) === 0) {
continue;
}
$required_fields = ['image', 'small_image', 'thumbnail', 'swatch_image'];
foreach ($existingMediaGalleryEntries as $key => $entry) {
$required_fields = array_diff($required_fields, $entry['types']);
if (count($required_fields) === 0) {
continue 2;
}
}
$slime = implode(' | ', $required_fields);
echo "{$product->getSku()} :: $slime", PHP_EOL;
$types = array_merge($required_fields, $existingMediaGalleryEntries[0]['types']);
$existingMediaGalleryEntries[0]->setTypes($types);
$product->setMediaGalleryEntries($existingMediaGalleryEntries);
$pri->save($product);
}
} |
Seems like it is still happening in 2.4.6 for me when I use
|
After upgrading from Magento 2.1.7 to 2.1.8 we had problems with product image roles. We have experienced that some products that previously had product image role set to
base
,small
,thumbnail
didn't have it anymore. It seems that the image roles get's removed from random products over time. This weekend at we have at least identified 10 products that got images roles removed during the weekend.Preconditions
Steps to reproduce
base
,small
,thumbnail
Expected result
base
,small
,thumbnail
unless the user changes it.Actual result
Short way to reproduce:
Preconditions
Create product with image and set role image:
base
,small
,thumbnail
Steps to reproduce
Save Product in backend controller like this:
Expected result
Product image roles should be set to
base
,small
,thumbnail
unless the user changes it.Actual result
Product image does not have any roles
The text was updated successfully, but these errors were encountered: