Skip to content

Commit d6b4a79

Browse files
committed
Merge remote-tracking branch 'origin/MC-35295' into 2.4-develop-pr32
2 parents 0787a68 + bd4b5ff commit d6b4a79

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ protected function _saveProducts()
15951595
}
15961596

15971597
$rowSku = $rowData[self::COL_SKU];
1598+
$rowSkuNormalized = mb_strtolower($rowSku);
15981599

15991600
if (null === $rowSku) {
16001601
$this->getErrorAggregator()->addRowToSkip($rowNum);
@@ -1604,9 +1605,9 @@ protected function _saveProducts()
16041605
$storeId = !empty($rowData[self::COL_STORE])
16051606
? $this->getStoreIdByCode($rowData[self::COL_STORE])
16061607
: Store::DEFAULT_STORE_ID;
1607-
$rowExistingImages = $existingImages[$storeId][$rowSku] ?? [];
1608+
$rowExistingImages = $existingImages[$storeId][$rowSkuNormalized] ?? [];
16081609
$rowStoreMediaGalleryValues = $rowExistingImages;
1609-
$rowExistingImages += $existingImages[Store::DEFAULT_STORE_ID][$rowSku] ?? [];
1610+
$rowExistingImages += $existingImages[Store::DEFAULT_STORE_ID][$rowSkuNormalized] ?? [];
16101611

16111612
if (self::SCOPE_STORE == $rowScope) {
16121613
// set necessary data from SCOPE_DEFAULT row
@@ -1762,10 +1763,11 @@ protected function _saveProducts()
17621763
continue;
17631764
}
17641765

1765-
if (isset($rowExistingImages[$uploadedFile])) {
1766-
$currentFileData = $rowExistingImages[$uploadedFile];
1766+
$uploadedFileNormalized = ltrim($uploadedFile, '/\\');
1767+
if (isset($rowExistingImages[$uploadedFileNormalized])) {
1768+
$currentFileData = $rowExistingImages[$uploadedFileNormalized];
17671769
$currentFileData['store_id'] = $storeId;
1768-
$storeMediaGalleryValueExists = isset($rowStoreMediaGalleryValues[$uploadedFile]);
1770+
$storeMediaGalleryValueExists = isset($rowStoreMediaGalleryValues[$uploadedFileNormalized]);
17691771
if (array_key_exists($uploadedFile, $imageHiddenStates)
17701772
&& $currentFileData['disabled'] != $imageHiddenStates[$uploadedFile]
17711773
) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ public function getExistingImages(array $bunch)
384384
foreach ($this->connection->fetchAll($select) as $image) {
385385
$storeId = $image['store_id'];
386386
unset($image['store_id']);
387-
$result[$storeId][$image['sku']][$image['value']] = $image;
387+
$sku = mb_strtolower($image['sku']);
388+
$value = ltrim($image['value'], '/\\');
389+
$result[$storeId][$sku][$value] = $image;
388390
}
389391

390392
return $result;

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,4 +3196,29 @@ public function testImportProductsWithLinksInDifferentBunches()
31963196
}
31973197
$this->assertEquals($linksData, $importedProductLinks);
31983198
}
3199+
3200+
/**
3201+
* Tests that image name does not have to be prefixed by slash
3202+
*
3203+
* @magentoDataFixture mediaImportImageFixture
3204+
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
3205+
* @magentoDataFixture Magento/Catalog/_files/product_with_image.php
3206+
*/
3207+
public function testUpdateImageByNameNotPrefixedWithSlash()
3208+
{
3209+
$expectedLabelForDefaultStoreView = 'image label updated';
3210+
$expectedImageFile = '/m/a/magento_image.jpg';
3211+
$secondStoreCode = 'fixturestore';
3212+
$productSku = 'simple';
3213+
$this->importDataForMediaTest('import_image_name_without_slash.csv');
3214+
$product = $this->getProductBySku($productSku);
3215+
$imageItems = $product->getMediaGalleryImages()->getItems();
3216+
$this->assertCount(1, $imageItems);
3217+
$imageItem = array_shift($imageItems);
3218+
$this->assertEquals($expectedImageFile, $imageItem->getFile());
3219+
$this->assertEquals($expectedLabelForDefaultStoreView, $imageItem->getLabel());
3220+
$product = $this->getProductBySku($productSku, $secondStoreCode);
3221+
$imageItems = $product->getMediaGalleryImages()->getItems();
3222+
$this->assertCount(0, $imageItems);
3223+
}
31993224
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"sku","store_view_code","base_image","base_image_label","hide_from_product_page"
2+
"simple",,"m/a/magento_image.jpg","image label updated",
3+
"simple","fixturestore",,,"m/a/magento_image.jpg"

0 commit comments

Comments
 (0)