Skip to content

Commit 447648e

Browse files
author
Oleksandr Iegorov
committed
MAGETWO-99927: Product URL rewrites are always regenerated if products are updated via CSV import in default scope
1 parent 7ce03f1 commit 447648e

File tree

1 file changed

+68
-129
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import

1 file changed

+68
-129
lines changed

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

Lines changed: 68 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,7 @@ public function getImagesFromRow(array $rowData)
15091509
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
15101510
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
15111511
* @throws LocalizedException
1512+
* phpcs:disable Generic.Metrics.NestingLevel
15121513
*/
15131514
protected function _saveProducts()
15141515
{
@@ -1689,27 +1690,73 @@ protected function _saveProducts()
16891690
* Note: to avoid problems with undefined sorting, the value of media gallery items positions
16901691
* must be unique in scope of one product.
16911692
*/
1692-
list(
1693-
$uploadedImages,
1694-
$rowData,
1695-
$mediaGallery,
1696-
$existingImages,
1697-
$labelsForUpdate,
1698-
$imagesForChangeVisibility
1699-
) = $this->processImages(
1700-
$rowImages,
1701-
$uploadedImages,
1702-
$rowData,
1703-
$rowNum,
1704-
$mediaGallery,
1705-
$storeId,
1706-
$rowSku,
1707-
$existingImages,
1708-
$rowLabels,
1709-
$labelsForUpdate,
1710-
$imageHiddenStates,
1711-
$imagesForChangeVisibility
1712-
);
1693+
$position = 0;
1694+
foreach ($rowImages as $column => $columnImages) {
1695+
foreach ($columnImages as $columnImageKey => $columnImage) {
1696+
if (!isset($uploadedImages[$columnImage])) {
1697+
$uploadedFile = $this->uploadMediaFiles($columnImage);
1698+
$uploadedFile = $uploadedFile ?: $this->getSystemFile($columnImage);
1699+
if ($uploadedFile) {
1700+
$uploadedImages[$columnImage] = $uploadedFile;
1701+
} else {
1702+
unset($rowData[$column]);
1703+
$this->addRowError(
1704+
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE,
1705+
$rowNum,
1706+
null,
1707+
null,
1708+
ProcessingError::ERROR_LEVEL_NOT_CRITICAL
1709+
);
1710+
}
1711+
} else {
1712+
$uploadedFile = $uploadedImages[$columnImage];
1713+
}
1714+
1715+
if ($uploadedFile && $column !== self::COL_MEDIA_IMAGE) {
1716+
$rowData[$column] = $uploadedFile;
1717+
}
1718+
1719+
if (!$uploadedFile || isset($mediaGallery[$storeId][$rowSku][$uploadedFile])) {
1720+
continue;
1721+
}
1722+
1723+
if (isset($existingImages[$rowSku][$uploadedFile])) {
1724+
$currentFileData = $existingImages[$rowSku][$uploadedFile];
1725+
if (isset($rowLabels[$column][$columnImageKey])
1726+
&& $rowLabels[$column][$columnImageKey] !=
1727+
$currentFileData['label']
1728+
) {
1729+
$labelsForUpdate[] = [
1730+
'label' => $rowLabels[$column][$columnImageKey],
1731+
'imageData' => $currentFileData
1732+
];
1733+
}
1734+
1735+
if (array_key_exists($uploadedFile, $imageHiddenStates)
1736+
&& $currentFileData['disabled'] != $imageHiddenStates[$uploadedFile]
1737+
) {
1738+
$imagesForChangeVisibility[] = [
1739+
'disabled' => $imageHiddenStates[$uploadedFile],
1740+
'imageData' => $currentFileData
1741+
];
1742+
}
1743+
} else {
1744+
if ($column == self::COL_MEDIA_IMAGE) {
1745+
$rowData[$column][] = $uploadedFile;
1746+
}
1747+
$mediaGallery[$storeId][$rowSku][$uploadedFile] = [
1748+
'attribute_id' => $this->getMediaGalleryAttributeId(),
1749+
'label' => isset($rowLabels[$column][$columnImageKey])
1750+
? $rowLabels[$column][$columnImageKey]
1751+
: '',
1752+
'position' => ++$position,
1753+
'disabled' => isset($imageHiddenStates[$columnImage])
1754+
? $imageHiddenStates[$columnImage] : '0',
1755+
'value' => $uploadedFile,
1756+
];
1757+
}
1758+
}
1759+
}
17131760

17141761
// 6. Attributes phase
17151762
$rowStore = (self::SCOPE_STORE == $rowScope)
@@ -3159,112 +3206,4 @@ private function composeLinkKey(int $productId, int $linkedId, int $linkTypeId)
31593206
{
31603207
return "{$productId}-{$linkedId}-{$linkTypeId}";
31613208
}
3162-
3163-
/**
3164-
* Process images
3165-
*
3166-
* @param array $rowImages
3167-
* @param array $uploadedImages
3168-
* @param array $rowData
3169-
* @param int $rowNum
3170-
* @param array $mediaGallery
3171-
* @param int $storeId
3172-
* @param string $rowSku
3173-
* @param array $existingImages
3174-
* @param array $rowLabels
3175-
* @param array $labelsForUpdate
3176-
* @param array $imageHiddenStates
3177-
* @param array $imagesForChangeVisibility
3178-
* @return array
3179-
*/
3180-
private function processImages(
3181-
array $rowImages,
3182-
array $uploadedImages,
3183-
array $rowData,
3184-
$rowNum,
3185-
array $mediaGallery,
3186-
$storeId,
3187-
$rowSku,
3188-
array $existingImages,
3189-
array $rowLabels,
3190-
array $labelsForUpdate,
3191-
array $imageHiddenStates,
3192-
array $imagesForChangeVisibility
3193-
): array {
3194-
$position = 0;
3195-
foreach ($rowImages as $column => $columnImages) {
3196-
foreach ($columnImages as $columnImageKey => $columnImage) {
3197-
if (!isset($uploadedImages[$columnImage])) {
3198-
$uploadedFile = $this->uploadMediaFiles($columnImage);
3199-
$uploadedFile = $uploadedFile ?: $this->getSystemFile($columnImage);
3200-
if ($uploadedFile) {
3201-
$uploadedImages[$columnImage] = $uploadedFile;
3202-
} else {
3203-
unset($rowData[$column]);
3204-
$this->addRowError(
3205-
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE,
3206-
$rowNum,
3207-
null,
3208-
null,
3209-
ProcessingError::ERROR_LEVEL_NOT_CRITICAL
3210-
);
3211-
}
3212-
} else {
3213-
$uploadedFile = $uploadedImages[$columnImage];
3214-
}
3215-
3216-
if ($uploadedFile && $column !== self::COL_MEDIA_IMAGE) {
3217-
$rowData[$column] = $uploadedFile;
3218-
}
3219-
3220-
if (!$uploadedFile || isset($mediaGallery[$storeId][$rowSku][$uploadedFile])) {
3221-
continue;
3222-
}
3223-
3224-
if (isset($existingImages[$rowSku][$uploadedFile])) {
3225-
$currentFileData = $existingImages[$rowSku][$uploadedFile];
3226-
if (isset($rowLabels[$column][$columnImageKey])
3227-
&& $rowLabels[$column][$columnImageKey] !=
3228-
$currentFileData['label']
3229-
) {
3230-
$labelsForUpdate[] = [
3231-
'label' => $rowLabels[$column][$columnImageKey],
3232-
'imageData' => $currentFileData
3233-
];
3234-
}
3235-
3236-
if (array_key_exists($uploadedFile, $imageHiddenStates)
3237-
&& $currentFileData['disabled'] != $imageHiddenStates[$uploadedFile]
3238-
) {
3239-
$imagesForChangeVisibility[] = [
3240-
'disabled' => $imageHiddenStates[$uploadedFile],
3241-
'imageData' => $currentFileData
3242-
];
3243-
}
3244-
} else {
3245-
if ($column == self::COL_MEDIA_IMAGE) {
3246-
$rowData[$column][] = $uploadedFile;
3247-
}
3248-
$mediaGallery[$storeId][$rowSku][$uploadedFile] = [
3249-
'attribute_id' => $this->getMediaGalleryAttributeId(),
3250-
'label' => isset($rowLabels[$column][$columnImageKey])
3251-
? $rowLabels[$column][$columnImageKey]
3252-
: '',
3253-
'position' => ++$position,
3254-
'disabled' => isset($imageHiddenStates[$columnImage])
3255-
? $imageHiddenStates[$columnImage] : '0',
3256-
'value' => $uploadedFile,
3257-
];
3258-
}
3259-
}
3260-
}
3261-
return [
3262-
$uploadedImages,
3263-
$rowData,
3264-
$mediaGallery,
3265-
$existingImages,
3266-
$labelsForUpdate,
3267-
$imagesForChangeVisibility
3268-
];
3269-
}
32703209
}

0 commit comments

Comments
 (0)