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 10 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
28 changes: 17 additions & 11 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/

namespace Magento\CatalogImportExport\Model\Import;
Expand Down Expand Up @@ -181,6 +181,11 @@ class Product extends AbstractEntity
*/
public const URL_KEY = 'url_key';

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

/**
* @var array
*/
Expand Down Expand Up @@ -337,7 +342,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 @@ -420,7 +425,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 @@ -1893,6 +1898,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 @@ -1950,19 +1956,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 @@ -2179,7 +2185,7 @@ private function getImagesHiddenStates($rowData)
{
$statesArray = [];
$mappingArray = [
'_media_is_disabled' => '1'
self::COL_MEDIA_IMAGE_HIDE => '1'
];

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