Skip to content

Bug/ac 12310 product image hide csv import #39034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ class Product extends AbstractEntity

private const ERROR_DUPLICATE_URL_KEY_BY_CATEGORY = 'duplicatedUrlKeyByCategory';

/**
* Hide from product page attribute code
*/
public const COL_MEDIA_IMAGE_HIDE = '_media_is_disabled';

/**
* @var array
*/
Expand Down Expand Up @@ -340,7 +345,7 @@ class Product extends AbstractEntity
'thumbnail_label' => 'thumbnail_image_label',
self::COL_MEDIA_IMAGE => 'additional_images',
'_media_image_label' => 'additional_image_labels',
'_media_is_disabled' => 'hide_from_product_page',
self::COL_MEDIA_IMAGE_HIDE => 'hide_from_product_page',
Product::COL_STORE => 'store_view_code',
Product::COL_ATTR_SET => 'attribute_set_code',
Product::COL_TYPE => 'product_type',
Expand Down Expand Up @@ -423,7 +428,7 @@ class Product extends AbstractEntity
self::COL_MEDIA_IMAGE,
'_media_label',
'_media_position',
'_media_is_disabled',
self::COL_MEDIA_IMAGE_HIDE
];

/**
Expand Down Expand Up @@ -1896,6 +1901,7 @@ private function saveProductMediaGalleryPhase(
$rowExistingImages += $existingImages[Store::DEFAULT_STORE_ID][$rowSkuNormalized] ?? [];
list($rowImages, $rowLabels) = $this->getImagesFromRow($rowData);
$imageHiddenStates = $this->getImagesHiddenStates($rowData);
$imageHideColumnExist = array_key_exists(self::COL_MEDIA_IMAGE_HIDE, $rowData);
foreach (array_keys($imageHiddenStates) as $image) {
//Mark image as uploaded if it exists
if (array_key_exists($image, $rowExistingImages)) {
Expand Down Expand Up @@ -1953,19 +1959,19 @@ private function saveProductMediaGalleryPhase(
continue;
}
$uploadedFileNormalized = ltrim($uploadedFile, '/\\');
$storeMediaGalleryValueExists = isset($rowStoreMediaGalleryValues[$uploadedFileNormalized]);
if (isset($rowExistingImages[$uploadedFileNormalized])) {
$currentFileData = $rowExistingImages[$uploadedFileNormalized];
$currentFileData['store_id'] = $storeId;
$storeMediaGalleryValueExists = isset($rowStoreMediaGalleryValues[$uploadedFileNormalized]);
if (array_key_exists($uploadedFile, $imageHiddenStates)
&& $currentFileData['disabled'] != $imageHiddenStates[$uploadedFile]
) {
if ($imageHideColumnExist) {
$imagesForChangeVisibility[] = [
'disabled' => $imageHiddenStates[$uploadedFile],
'disabled' => array_key_exists(
$uploadedFile,
$imageHiddenStates
) ? $imageHiddenStates[$uploadedFile] : '0',
'imageData' => $currentFileData,
'exists' => $storeMediaGalleryValueExists
];
$storeMediaGalleryValueExists = true;
}
if (isset($rowLabels[$column][$columnImageKey])
&& $rowLabels[$column][$columnImageKey] !== $currentFileData['label']
Expand Down Expand Up @@ -2182,7 +2188,7 @@ private function getImagesHiddenStates($rowData)
{
$statesArray = [];
$mappingArray = [
'_media_is_disabled' => '1'
self::COL_MEDIA_IMAGE_HIDE => '1'
];

foreach ($mappingArray as $key => $value) {
Expand Down