Skip to content

Commit 02d35c4

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-3972' into PR_2025_07_08_muntianu
2 parents f50423c + ac54833 commit 02d35c4

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,43 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData, $
987987
return true;
988988
}
989989

990+
/**
991+
* Create disable image details
992+
*
993+
* @param mixed $rowSku
994+
* @param mixed $column
995+
* @param mixed $rowExistingImages
996+
* @param int $storeId
997+
* @return array|null
998+
*/
999+
private function disableExistingProductImage(
1000+
mixed $rowSku,
1001+
mixed $column,
1002+
mixed $rowExistingImages,
1003+
int $storeId
1004+
): ?array {
1005+
try {
1006+
$product = $this->productRepository->get($rowSku);
1007+
if ($imagePath = $product->getData($column)) {
1008+
foreach ($rowExistingImages as $existingImage) {
1009+
if ($existingImage['value'] == $imagePath) {
1010+
$existingImage['store_id'] = $storeId;
1011+
1012+
return [
1013+
'disabled' => 1,
1014+
'imageData' => $existingImage,
1015+
'exists' => true
1016+
];
1017+
}
1018+
}
1019+
}
1020+
} catch (NoSuchEntityException) {
1021+
return null;
1022+
}
1023+
1024+
return null;
1025+
}
1026+
9901027
/**
9911028
* Multiple value separator getter.
9921029
*
@@ -1918,6 +1955,14 @@ private function saveProductMediaGalleryPhase(
19181955
$imagesByHash = [];
19191956
foreach ($rowImages as $column => $columnImages) {
19201957
foreach ($columnImages as $columnImageKey => $columnImage) {
1958+
if ($columnImage == $this->getEmptyAttributeValueConstant()) {
1959+
if ($disabledImageDetails =
1960+
$this->disableExistingProductImage($rowSku, $column, $rowExistingImages, $storeId)
1961+
) {
1962+
$imagesForChangeVisibility[] = $disabledImageDetails;
1963+
}
1964+
continue;
1965+
}
19211966
$uploadedFile = $this->findImageByColumnImage(
19221967
$productMediaPath,
19231968
$rowExistingImages,

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -115,6 +115,42 @@ public function testImportProductsWithSameImages(): void
115115
$this->checkProductsImages('/m/a/magento_image.jpg', $this->createdProductsSkus);
116116
}
117117

118+
/**
119+
* @return void
120+
* @throws NoSuchEntityException
121+
*/
122+
public function testHideImageWhenColumnContainsEmptyValue(): void
123+
{
124+
$productSku = 'ABC';
125+
$this->moveImages('magento_image.jpg');
126+
$source = $this->prepareFile('catalog_import_products_with_swatch_image.csv');
127+
$this->updateUploader();
128+
$errors = $this->import->setParameters([
129+
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
130+
'entity' => ProductEntity::ENTITY,
131+
])
132+
->setSource($source)->validateData();
133+
$this->assertEmpty($errors->getAllErrors());
134+
$this->import->importData();
135+
$this->createdProductsSkus[] = $productSku;
136+
$this->checkProductsImages('/m/a/magento_image.jpg', $this->createdProductsSkus);
137+
138+
$this->importDataResource->cleanBunches();
139+
$source = $this->prepareFile('catalog_import_products_without_swatch_image.csv');
140+
$this->updateUploader();
141+
$errors = $this->import->setParameters([
142+
'behavior' => Import::BEHAVIOR_ADD_UPDATE,
143+
'entity' => ProductEntity::ENTITY,
144+
])
145+
->setSource($source)->validateData();
146+
$this->assertEmpty($errors->getAllErrors());
147+
$this->import->importData();
148+
$this->productRepository->cleanCache();
149+
$product = $this->productRepository->get($productSku);
150+
$images = $product->getMediaGalleryImages();
151+
$this->assertEmpty($images->getItems());
152+
}
153+
118154
/**
119155
* Check product images
120156
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,name,swatch_image,swatch_image_label,attribute_set_code,product_type,product_websites
2+
ABC,abc,magento_image.jpg,testing,Default,simple,base
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,name,swatch_image,swatch_image_label
2+
ABC,abc,__EMPTY__VALUE__,__EMPTY__VALUE__

0 commit comments

Comments
 (0)