Closed simonworkhouse closed 3 years ago
Hi @simonworkhouse. Thank you for your report. To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento-engcom-team give me 2.3-develop instance
- upcoming 2.3.x release
For more details, please, review the Magento Contributor Assistant documentation.
@simonworkhouse do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?
Hi @engcom-backlog-nazar. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Verify that the issue is reproducible on 2.2-develop
branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop
branch, please add the label Reproduced on 2.2.x
Next steps are available in case you are a member of Community Maintainers.
[ ] 6. Add label Issue: Confirmed
once verification is complete.
[ ] 7. Make sure that automatic system confirms that report has been added to the backlog.
@magento-engcom-team give me 2.3-develop instance
Hi @dipti2jcommerce. Thank you for your request. I'm working on Magento 2.3-develop instance for you
Hi @dipti2jcommerce, here is your Magento instance.
Admin access: https://i-21885-2-3-develop.instances.magento-community.engineering/admin
Login: admin
Password: 123123q
Instance will be terminated in up to 3 hours.
:white_check_mark: Confirmed by @engcom-backlog-nazar
Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-98840
were created
Issue Available: @engcom-backlog-nazar, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
I would like to share some point about the issue. It happens in Magento\CatalogImportExport\Model\Import\Product.php line 1772. If add a variable for exists images in mapper like _media_is_disabled, it should be fix it but the code try to match it with path. That why it doesn't work.
Thank you for the information @tnsezer
Duplicate of #14398
See PR here: https://github.com/magento/magento2/pull/21146
Actually, there's a better PR here, based on mine but it also deals with image deletion: https://github.com/magento/magento2/pull/21855
@erfanimani thanks for the update. Are the issues duplicated or the PRs?
@dmanners Both actually — this issue is a duplicate of #14398
But then there are two open PRs (I referenced them both in case someone wants to create a patch for it):
I am working on this at #dmcdindia1
@soundararajanm1990 thank you for joining. Please accept team invitation here and self-assign the issue.
Hi @soundararajanm1990. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:
[ ] 1. Add/Edit Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 2. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 3. Verify that the issue is reproducible on 2.2-develop
branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop
branch, please add the label Reproduced on 2.2.x
[ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.
Hi @soundararajanm1990,
Have you fixed this issue? its also coming when trying to Duplicate product.
Thanks Yogesh
what's the status on this issue?
We can't solve this issue. Still now pending.
We are encountering this too and since the import is ran daily this really clutters up the media gallery. Is there any workaround anyone can recommend?
I have same problem, magento2.3.2 duplicated images after import product csv.
Did you find a solution ?
Two workarounds exist, scroll up to see the relevant pull requests/commits. You'll need a developer to create and apply Composer patches for your Magento version. Seems Magento is too busy to review/merge and fix the bug themselves though..
@erfanimani Yes, we indeed used a combination of the solutions (with some minor edits). Really odd that Magento doesn't look at the fixes because the importer is a vital part of most webshops.
Thank you @erfanimani
With a combination of the solutions, the import works very well.
+1 Hoping to see this merged in soon, big help this :)
Wow same trouble for us... This is awsome magento let this kind of BUG in a 2.3.2 version released worldwild...
@kevinvuillemin can you share the working solution ? I'm strugeling with all the PR closed and open speaking around it. Thank you in advance
@skapin, of course ! how do you want me to share the file?
@kevinvuillemin you can send me a mail to skapinthefourb gmailcom address for example, or create a repository
As you want. Thank you so much :)
@skapin that's good for you ?
https://gist.github.com/kevinvuillemin/802cc5e4b476e73c1c5838b143bd6a51
@kevinvuillemin It works on the first try. Copy/paste instead of Product.php and voila ! Magento version : 2.3.2
Et voila ! Au plaisir ;-)
@kevinvuillemin Your code not working in Magento version : 2.3.1
Working with 2.3.2 for me, are you sure ?
yes we used 2.3.1 not working
@soundararajanm1990 I think they have changed the Product.php class for the release of Magento 2.3.2.
The easier is to upgrade (maintenance & safety)
@kevinvuillemin They moved the issue #14398 onto a new phase - does this mean your PR is ready for Testing on the next Dev version?
any update on this issue?
Below is a more permanent solution.
Be careful, this will trash previous duplicates if there were any.
Make a preference on Magento\CatalogImportExport\Model\Import\Product
and copy/paste this code in it:
use const DIRECTORY_SEPARATOR;
class Product extends \Magento\CatalogImportExport\Model\Import\Product
{
private $bunch;
private $imagesToRemove;
protected function getExistingImages($bunch)
{
$this->bunch = $bunch;
return parent::getExistingImages($bunch);
}
public function addImageHashes(&$imagesBySku)
{
parent::addImageHashes($imagesBySku);
// get existing images (from db)
$existingImages = [];
foreach ($imagesBySku as $sku => $images) {
foreach ($images as $path => $imageInfo) {
if (!isset($existingImages[$imageInfo['hash']])) {
$existingImages[$imageInfo['hash']] = [];
}
$existingImages[$imageInfo['hash']][] = [
'value_id' => $imageInfo['value_id'],
'path' => $path
];
}
}
// get imported images (from file)
$importDir = $this->_mediaDirectory->getAbsolutePath($this->getImportDir());
$importedImages = [];
foreach ($this->bunch as $rowData) {
foreach ($this->getImagesFromRow($rowData)[0] as $imagesFromRow) {
$imageNames = explode($this->getMultipleValueSeparator(), $imagesFromRow[0]);
$imageHashes = array_flip(array_map(function($imageName) use ($importDir) {
$filename = $importDir . DIRECTORY_SEPARATOR . $imageName;
return $this->_mediaDirectory->isReadable($filename) ? md5_file($filename) : '';
}, $imageNames));
$importedImages = array_merge($importedImages, $imageHashes);
}
}
// guess images to remove
$this->imagesToRemove = array_diff_key($existingImages, $importedImages);
}
protected function _saveMediaGallery(array $mediaGalleryData)
{
// remove duplicate images
$valueIds = [];
if (!empty($this->imagesToRemove)) {
// from disk
foreach ($this->imagesToRemove as $imagesToRemove) {
foreach ($imagesToRemove as $imageToRemove) {
$imagePath = 'pub/media/catalog/product' . $imageToRemove['path'];
if ($this->_mediaDirectory->isExist($imagePath)) {
$this->_mediaDirectory->delete($imagePath);
}
$valueIds[] = $imageToRemove['value_id'];
}
}
// from database
$this->getConnection()->delete(
$this->getConnection()->getTableName('catalog_product_entity_media_gallery'),
$this->getConnection()->quoteInto('value_id IN (?)', $valueIds)
);
}
return parent::_saveMediaGallery($mediaGalleryData);
}
}
Well sadly this looks like it missed the 2.3.3 ship :(
Realy ? That’s not cool.
But This fix working ? :
https://gist.github.com/kevinvuillemin/802cc5e4b476e73c1c5838b143bd6a51
Normally I would be surprised that it has been so long without a resolution, but I have come to expect this from Magento. Anyway, I have had to resolve this issue for a project recently and it appears that the offending commit was https://github.com/magento/magento2/commit/7803eed11f8bf490bf8905ab0577091c7e782156
I worked around this by adding a preference for a class that extends Magento\CatalogImportExport\Model\Import\Product
and just overrides the uploadMediaFiles(...)
function to force the $renameFileOff
variable to be true
.
This addresses the issue in our specific use case, but it does not address the underlying issues with the way that images are managed in Magento. Additionally, it will also undo whatever "fix" that commit was attempting to do.
@simonworkhouse Can you please share the code with me?
version 2.3.3 Atttached is the patch that is used to fix the issue in our use case. Magento import is expecting images to have the dynamic paths it created on export. However, the CSV is hand crafted and the image names are plain; "blablabla.jpg" as opposed to "/b/l/a/blablabla_60.jpg". This patch works repeatedly because the CSV file is from the same feed. The patch basically strips off the "/b/l/a/" and "_60" and makes a match to the existing image(s) for that product.
Does anyone have a fix for 2.3.3 with an including fix to remove duplicates? Our server just exploded to 55gb on images because of the duplication during the import..
the commit that @simonworkhouse referred to, was the suicide bomber in our case as well. Patching that to the previous implementation fixed it. In my opinion this really should be reverted.
@jalung 's patch worked for me, except for that Magento 2.3.3 (if not earlier versions) renames images all lowercase, so the image name preg_match needs to be case insensitive. Patch with that change here: Product-revised-version.txt
Product-revised-version.txt Fixed case where CSV row has new and existing images.
Also missed the 2.3.4 ship. @jalung 's patch is working fine for me in 2.3.4. Still needs more testing, for my case, where images are updated by sku, but have same name.jpg.
Possible fix in https://github.com/magento/magento2/pull/26713
I've seen some change in the codebase of Magento 2.3.5 which might fix this issue. Would be great if somebody could verify this after 2.3.5 is officially released on 28 April.
When importing product data the product images are being duplicated for each import run.
Preconditions
Steps to reproduce
<install dir>
<install dir>
test-1.jpg
,test-2.jpg
,test-3.jpg
andtest-4.jpg
inside the path<install dir>/var/import-images
. Any valid jpeg will do.Import settings
__EMPTY__VALUE__
(default)Expected result
Products end up with each product image only attached once.
Actual result
Products end up with all product images duplicated.