Skip to content

Commit cac6fb4

Browse files
author
Oleksii Korshenko
authored
MAGETWO-88240: product images with same name overwrite previous image fix #99
2 parents 87e96d3 + a2119af commit cac6fb4

File tree

2 files changed

+36
-2
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import
  • dev/tests/integration/testsuite/Magento/CatalogImportExport/Model

2 files changed

+36
-2
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ protected function _saveProducts()
17121712
foreach ($rowImages as $column => $columnImages) {
17131713
foreach ($columnImages as $columnImageKey => $columnImage) {
17141714
if (!isset($uploadedImages[$columnImage])) {
1715-
$uploadedFile = $this->uploadMediaFiles($columnImage, true);
1715+
$uploadedFile = $this->uploadMediaFiles($columnImage);
17161716
$uploadedFile = $uploadedFile ?: $this->getSystemFile($columnImage);
17171717
if ($uploadedFile) {
17181718
$uploadedImages[$columnImage] = $uploadedFile;

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/ProductTest.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,16 @@ public function exportImportDataProvider()
9797
'simple-product-image' => [
9898
[
9999
'Magento/CatalogImportExport/Model/Import/_files/media_import_image.php',
100-
'Magento/Catalog/_files/product_with_image.php'
100+
'Magento/Catalog/_files/product_with_image.php',
101101
],
102102
[
103103
'simple',
104+
],
105+
[
106+
"image",
107+
"small_image",
108+
"thumbnail",
109+
"media_gallery"
104110
]
105111
],
106112
'simple-product-crosssell' => [
@@ -134,4 +140,32 @@ public function importReplaceDataProvider()
134140
{
135141
return $this->exportImportDataProvider();
136142
}
143+
144+
/**
145+
* Fixing https://github.com/magento-engcom/import-export-improvements/issues/50 means that during import images
146+
* can now get renamed for this we need to skip the attribute checking and instead check that the images contain
147+
* the right beginning part of the name. When an image is named "magento_image.jpeg" but there is already an image
148+
* with that name it will now become "magento_image_1.jpeg"
149+
*
150+
* @param \Magento\Catalog\Model\Product $expectedProduct
151+
* @param \Magento\Catalog\Model\Product $actualProduct
152+
*/
153+
protected function assertEqualsSpecificAttributes($expectedProduct, $actualProduct)
154+
{
155+
if (!empty($actualProduct->getImage())
156+
&& !empty($expectedProduct->getImage())
157+
) {
158+
$this->assertContains('magento_image', $actualProduct->getImage());
159+
}
160+
if (!empty($actualProduct->getSmallImage())
161+
&& !empty($expectedProduct->getSmallImage())
162+
) {
163+
$this->assertContains('magento_image', $actualProduct->getSmallImage());
164+
}
165+
if (!empty($actualProduct->getThumbnail())
166+
&& !empty($expectedProduct->getThumbnail())
167+
) {
168+
$this->assertContains('magento_image', $actualProduct->getThumbnail());
169+
}
170+
}
137171
}

0 commit comments

Comments
 (0)