Skip to content

Commit 4e0dfe9

Browse files
committed
ACP2E-3972: Csv product import : Unable to unset a swatch image
1 parent 71ea445 commit 4e0dfe9

File tree

1 file changed

+45
-0
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import

1 file changed

+45
-0
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,42 @@ 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+
}
1022+
1023+
return null;
1024+
}
1025+
9901026
/**
9911027
* Multiple value separator getter.
9921028
*
@@ -1682,6 +1718,7 @@ protected function _saveProducts()
16821718
$this->saveProductToWebsitePhase($rowData);
16831719
$this->saveProductCategoriesPhase($rowNum, $rowData);
16841720
$this->saveProductTierPricesPhase($rowData, $priceIsGlobal, $tierPrices);
1721+
$imagesToBeRemoved = [];
16851722
$this->saveProductMediaGalleryPhase(
16861723
$rowNum,
16871724
$rowData,
@@ -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,

0 commit comments

Comments
 (0)