Skip to content

Commit e46c8fd

Browse files
committed
8255: Export Products action doesn't consider hide_for_product_page value.
1 parent a22d223 commit e46c8fd

File tree

3 files changed

+6
-53
lines changed

3 files changed

+6
-53
lines changed

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,17 +1670,10 @@ protected function _saveProducts()
16701670
$disabledImages = array_flip(
16711671
explode($this->getMultipleValueSeparator(), $rowData['_media_is_disabled'])
16721672
);
1673-
foreach ($disabledImages as $disabledImage => $position) {
1674-
$uploadedFile = $this->uploadMediaFiles($disabledImage, true);
1675-
$uploadedFile = $uploadedFile ?: $this->getSystemFile($disabledImage);
1676-
$mediaGallery[$storeId][$rowSku][$uploadedFile] = [
1677-
'attribute_id' => $this->getMediaGalleryAttributeId(),
1678-
'label' => $rowLabels[self::COL_MEDIA_IMAGE][$position] ?? '',
1679-
'position' => $position,
1680-
'disabled' => 1,
1681-
'value' => $disabledImage,
1682-
'store_id' => $storeId,
1683-
];
1673+
if (empty($rowImages)) {
1674+
foreach (array_keys($disabledImages) as $disabledImage) {
1675+
$rowImages[self::COL_MEDIA_IMAGE][] = $disabledImage;
1676+
}
16841677
}
16851678
}
16861679
$rowData[self::COL_MEDIA_IMAGE] = [];
@@ -1740,10 +1733,6 @@ protected function _saveProducts()
17401733
}
17411734
}
17421735

1743-
//Add images to restore "hide from product page" value for specified store and product.
1744-
if (empty($mediaGallery[$storeId][$rowSku])) {
1745-
$mediaGallery[$storeId][$rowSku]['all'] = ['restore' => true];
1746-
}
17471736
// 6. Attributes phase
17481737
$rowStore = (self::SCOPE_STORE == $rowScope)
17491738
? $this->storeResolver->getStoreCodeToId($rowData[self::COL_STORE])

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

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public function __construct(
109109
public function saveMediaGallery(array $mediaGalleryData)
110110
{
111111
$this->initMediaGalleryResources();
112-
$mediaGalleryData = $this->restoreDisabledImage($mediaGalleryData);
113112
$mediaGalleryDataGlobal = array_replace_recursive(...$mediaGalleryData);
114113
$imageNames = [];
115114
$multiInsertData = [];
@@ -134,9 +133,7 @@ public function saveMediaGallery(array $mediaGalleryData)
134133
$this->connection->select()->from($this->mediaGalleryTableName, ['value_id', 'value'])
135134
->where('value IN (?)', $imageNames)
136135
);
137-
if (!empty($multiInsertData)) {
138-
$this->connection->insertOnDuplicate($this->mediaGalleryTableName, $multiInsertData);
139-
}
136+
$this->connection->insertOnDuplicate($this->mediaGalleryTableName, $multiInsertData);
140137
$newMediaSelect = $this->connection->select()->from($this->mediaGalleryTableName, ['value_id', 'value'])
141138
->where('value IN (?)', $imageNames);
142139
if (array_keys($oldMediaValues)) {
@@ -263,39 +260,6 @@ private function initMediaGalleryResources()
263260
}
264261
}
265262

266-
/**
267-
* Set product images 'disable' = 0 for specified store.
268-
*
269-
* @param array $mediaGalleryData
270-
* @return array
271-
*/
272-
private function restoreDisabledImage(array $mediaGalleryData)
273-
{
274-
$restoreData = [];
275-
foreach (array_keys($mediaGalleryData) as $storeId) {
276-
foreach ($mediaGalleryData[$storeId] as $productSku => $mediaGalleryRows) {
277-
$productId = $this->skuProcessor->getNewSku($productSku)[$this->getProductEntityLinkField()];
278-
$restoreData[] = sprintf(
279-
'store_id = %s and %s = %s',
280-
$storeId,
281-
$this->getProductEntityLinkField(),
282-
$productId
283-
);
284-
if (isset($mediaGalleryRows['all']['restore'])) {
285-
unset($mediaGalleryData[$storeId][$productSku]);
286-
}
287-
}
288-
}
289-
290-
$this->connection->update(
291-
$this->mediaGalleryValueTableName,
292-
['disabled' => 0],
293-
new \Zend_Db_Expr(implode(' or ', $restoreData))
294-
);
295-
296-
return $mediaGalleryData;
297-
}
298-
299263
/**
300264
* Save media gallery data per store.
301265
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ public function testImportImageForNonDefaultStore()
19831983
$product = $this->getProductBySku('simple_with_images');
19841984
$mediaGallery = $product->getData('media_gallery');
19851985
foreach ($mediaGallery['images'] as $image) {
1986-
$image['file'] === 'magento_image.jpg'
1986+
$image['file'] === '/m/a/magento_image.jpg'
19871987
? self::assertSame('1', $image['disabled'])
19881988
: self::assertSame('0', $image['disabled']);
19891989
}

0 commit comments

Comments
 (0)